PreprocMEG.m 162 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688
  1. function varargout = PreprocMEG(varargin)
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. % Reads MEG data into Fieldtrip and runs preprocessing. %
  4. % See: "help ft_read_header" for supported filetypes. %
  5. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  6. % Copyright (C) 2013-2014, Michael J. Cheung
  7. %
  8. % This file is a part of the MEG & PLS Pipeline (MEGPLS). For more
  9. % details, see the documentation included with the software package.
  10. %
  11. % MEGPLS is free software: you can redistribute it and/or modify it under
  12. % the terms of the GNU General Public License version 2 as published by
  13. % the Free Software Foundation. This program is distributed in the hope
  14. % that it will be useful, but WITHOUT ANY WARRANTY; without even the
  15. % implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. % See the GNU General Public License for more details.
  17. %
  18. % You should have received a copy of the GNU General Public License along
  19. % with this program. If not, you can download the license here:
  20. % <http://www.gnu.org/licenses/old-licenses/gpl-2.0>.
  21. % Last Modified by GUIDE v2.5 11-Jul-2014 17:49:28
  22. % Begin initialization code - DO NOT EDIT
  23. gui_Singleton = 1;
  24. gui_State = struct('gui_Name', mfilename, ...
  25. 'gui_Singleton', gui_Singleton, ...
  26. 'gui_OpeningFcn', @PreprocMEG_OpeningFcn, ...
  27. 'gui_OutputFcn', @PreprocMEG_OutputFcn, ...
  28. 'gui_LayoutFcn', [] , ...
  29. 'gui_Callback', []);
  30. if nargin && ischar(varargin{1})
  31. gui_State.gui_Callback = str2func(varargin{1});
  32. end
  33. if nargout
  34. [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  35. else
  36. gui_mainfcn(gui_State, varargin{:});
  37. end
  38. % End initialization code - DO NOT EDIT
  39. %=======================%
  40. % INITIALIZE GUIDE GUI: %
  41. %=======================%
  42. %--- Executes just before PreprocMEG is made visible. ---%
  43. %--------------------------------------------------------------%
  44. function PreprocMEG_OpeningFcn(hObject, eventdata, handles, varargin)
  45. % This function has no output args, see OutputFcn.
  46. % hObject handle to figure
  47. % eventdata reserved - to be defined in a future version of MATLAB
  48. % handles structure with handles and user data (see GUIDATA)
  49. % varargin command line arguments to PreprocMEG (see VARARGIN)
  50. % Choose default command line output for PreprocMEG
  51. handles.output = hObject;
  52. % Make sure toolbox paths are added:
  53. [PipelineDir, ~, ~] = fileparts(which('PreprocMEG.m'));
  54. addpath(genpath(PipelineDir));
  55. rmpath([PipelineDir,'/DEFAULT_SETTINGS']); % Make sure its calling from AnalysisID
  56. rmpath([PipelineDir,'/TEMPORARY_FIXES']); % Make sure its calling from FT toolbox
  57. CheckToolboxPaths(PipelineDir);
  58. if exist('ErrorLog_PreprocMEG.txt', 'file')
  59. delete('ErrorLog_PreprocMEG.txt');
  60. end
  61. % Initializes variables being displayed:
  62. handles.paths.Rootpath = [];
  63. handles.paths.DataID = [];
  64. handles.name.DataID = [];
  65. handles.name.CurrentGroupID = [];
  66. handles.paths.CurrentGroupID = [];
  67. handles.name.SubjID = [];
  68. handles.gui.Status = [];
  69. handles.paths.DataFolder = [];
  70. handles.paths.DataFile = [];
  71. handles.paths.DataFullpath = [];
  72. handles.gui.DataFiletype = 'CTFds';
  73. handles.gui.ReadHdrSuccess = [];
  74. handles.gui.DataContinuous = [];
  75. handles.gui.InputNumTrials = [];
  76. handles.gui.EventInfoExist = [];
  77. handles.gui.AllEventInfo = [];
  78. handles.name.CondID = [];
  79. handles.name.CurrentCondID = [];
  80. handles.paths.CurrentCondID = [];
  81. handles.gui.DetectedEvents = [];
  82. handles.epoch.TargetMarkers = [];
  83. handles.epoch.IncludedEvents = [];
  84. handles.epoch.ExcludedEvents = [];
  85. handles.time.Start = [];
  86. handles.time.End = [];
  87. handles.time.OverlapThresh = [];
  88. handles.time.IncEventStart = [];
  89. handles.time.IncEventEnd = [];
  90. handles.time.ExcEventStart = [];
  91. handles.time.ExcEventEnd = [];
  92. handles.FTcfg = [];
  93. handles.gui.LockPreprocSettings = 'off';
  94. % Save handles:
  95. guidata(hObject, handles);
  96. % UIWAIT makes PreprocMEG wait for user response (see UIRESUME)
  97. % uiwait(handles.PreprocGUI);
  98. %** FOR NEUROMAG DATA, NEED TO SET BITRATE IN FT_PREPROCESSING:
  99. % - Ex: cfg.headerformat, cfg.dataformat, cfg.eventformat = 'ns_cnt32'
  100. % - Have options here to select bitrate.
  101. %--- Outputs from this function are returned to the command line. ---%
  102. %--------------------------------------------------------------------%
  103. function varargout = PreprocMEG_OutputFcn(hObject, eventdata, handles)
  104. % varargout cell array for returning output args (see VARARGOUT);
  105. % hObject handle to figure
  106. % eventdata reserved - to be defined in a future version of MATLAB
  107. % handles structure with handles and user data (see GUIDATA)
  108. % Get default command line output from handles structure
  109. varargout{1} = handles.output;
  110. %===================================%
  111. % FUNCTIONS FOR SELECTING ROOTPATH: %
  112. %===================================%
  113. %--- Executes on button press in ButtonSetRootpath. ---%
  114. %------------------------------------------------------%
  115. function ButtonSetRootpath_Callback(hObject, eventdata, handles)
  116. if ~isempty(handles.name.DataID)
  117. prompt = {'WARNING:'; '';
  118. 'Changing root directory will clear all current settings!'; '';
  119. 'Do you wish to continue?'};
  120. ChangeDir = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'NO');
  121. if strcmp(ChangeDir, 'NO')
  122. return;
  123. end
  124. end
  125. % Select and set Rootpath:
  126. SelectedPath = uigetdir;
  127. if SelectedPath == 0
  128. return % If user cancels
  129. end
  130. % Check if selected path has spaces (AFNI functions cannot read spaces):
  131. CheckSpaces = strfind(SelectedPath, ' ');
  132. if ~isempty(CheckSpaces)
  133. message = {'Error: Target directory selected contains spaces.';
  134. 'AFNI functions cannot read folder & file paths with spaces.';
  135. 'AFNI functions are required for file conversions later on.'};
  136. msgbox(message, 'Error:')
  137. return;
  138. end
  139. handles.paths.Rootpath = SelectedPath;
  140. set(handles.TextboxRootpath, 'String', handles.paths.Rootpath);
  141. % Start Waitbox:
  142. WaitBox = StartWaitBox('SETTING ROOT DIRECTORY:');
  143. % Reset DataID:
  144. handles.name.DataID = [];
  145. handles.paths.DataID = [];
  146. set(handles.TextboxDataID, 'String', 'Not Selected.');
  147. % Reset GroupID:
  148. handles.name.CurrentGroupID = [];
  149. handles.paths.CurrentGroupID = [];
  150. set(handles.TextboxGroupID, 'String', 'Not Selected.');
  151. % Reset settings & GUI panels:
  152. handles = ResetSubjIDSettings (handles);
  153. handles = ResetInputDataSettings (handles);
  154. handles = ResetEventSettings (handles);
  155. handles = ResetCondIDSettings (handles);
  156. handles = ResetStatusSettings (handles);
  157. handles = ResetEpochSettings (handles);
  158. handles = ResetBaselineSettings (handles);
  159. handles = ResetGeneralFilterSettings (handles);
  160. handles = ResetBandstopFilterSettings (handles);
  161. handles = ResetDFTFilterSettings (handles);
  162. handles = ResetMedianFilterSettings (handles);
  163. handles = ResetDetrendSettings (handles);
  164. handles = ResetOtherAdvSettings (handles);
  165. % Unlock settings if locked:
  166. handles.gui.LockPreprocSettings = 'off';
  167. set(handles.ButtonSaveLockSettings, 'Enable', 'on');
  168. set(handles.ButtonLoadPreprocSettings, 'Enable', 'on');
  169. % Update settings & GUI panels (to enable/disable & unlock):
  170. % Note: Don't redetect CondID / Status yet since GroupID reset.
  171. handles = UpdateSubjIDSettings (handles);
  172. handles = UpdateInputDataSettings (handles);
  173. handles = UpdateEventSettings (handles);
  174. handles = UpdateCondIDSettings (handles);
  175. handles = UpdateStatusSettings (handles);
  176. handles = UpdateEpochSettings (handles);
  177. handles = UpdateBaselineSettings (handles);
  178. handles = UpdateGeneralFilterSettings (handles);
  179. handles = UpdateBandstopFilterSettings (handles);
  180. handles = UpdateDFTFilterSettings (handles);
  181. handles = UpdateMedianFilterSettings (handles);
  182. handles = UpdateDetrendSettings (handles);
  183. handles = UpdateOtherAdvSettings (handles);
  184. % Save handles:
  185. guidata(hObject, handles);
  186. close(WaitBox);
  187. %--- Textbox to display selected Rootpath: ---%
  188. %---------------------------------------------%
  189. function TextboxRootpath_Callback(hObject, eventdata, handles)
  190. EnteredText = get(handles.TextboxRootpath, 'String');
  191. if ~isequal(EnteredText, handles.paths.Rootpath)
  192. set(handles.TextboxRootpath, 'String', handles.paths.Rootpath);
  193. msgbox('Note: Use button to change Rootpath.')
  194. end
  195. %===========================================%
  196. % FUNCTIONS FOR CREATING OR LOADING DATAID: %
  197. %===========================================%
  198. %--- Executes on button press in ButtonCreateDataID. ---%
  199. %-------------------------------------------------------%
  200. function ButtonCreateDataID_Callback(hObject, eventdata, handles)
  201. if isempty(handles.paths.Rootpath)
  202. msgbox('Warning: Select root directory first.', 'Warning:');
  203. return;
  204. end
  205. % Enter name of DataID:
  206. UserInput = inputdlg('Enter DataID name:', 'Create new DataID:');
  207. UserInput = deblank(UserInput);
  208. UserInput = regexprep(UserInput, '\s+', '_');
  209. if isempty(char(UserInput))
  210. return; % If user cancels
  211. end
  212. PathInputID = [handles.paths.Rootpath,'/DataID_',UserInput{1}];
  213. if exist(PathInputID, 'dir')
  214. msgbox('Error: Specified DataID already exists!', 'Error:')
  215. return;
  216. end
  217. % Set DataID & create folder:
  218. status = mkdir(PathInputID);
  219. if status == 1 % If mkdir successful
  220. handles.name.DataID = UserInput{1};
  221. handles.paths.DataID = PathInputID;
  222. set(handles.TextboxDataID, 'String', handles.name.DataID);
  223. else
  224. msgbox('Error: Failed to create DataID folder.', 'Error:')
  225. return;
  226. end
  227. % Start Waitbox:
  228. WaitBox = StartWaitBox('CREATING DATA ID:');
  229. % Reset GroupID:
  230. handles.name.CurrentGroupID = [];
  231. handles.paths.CurrentGroupID = [];
  232. set(handles.TextboxGroupID, 'String', 'None Selected');
  233. % Reset settings & GUI panels:
  234. handles = ResetSubjIDSettings (handles);
  235. handles = ResetInputDataSettings (handles);
  236. handles = ResetEventSettings (handles);
  237. handles = ResetCondIDSettings (handles);
  238. handles = ResetStatusSettings (handles);
  239. handles = ResetEpochSettings (handles);
  240. handles = ResetBaselineSettings (handles);
  241. handles = ResetGeneralFilterSettings (handles);
  242. handles = ResetBandstopFilterSettings (handles);
  243. handles = ResetDFTFilterSettings (handles);
  244. handles = ResetMedianFilterSettings (handles);
  245. handles = ResetDetrendSettings (handles);
  246. handles = ResetOtherAdvSettings (handles);
  247. % Unlock settings if locked:
  248. handles.gui.LockPreprocSettings = 'off';
  249. set(handles.ButtonSaveLockSettings, 'Enable', 'on');
  250. set(handles.ButtonLoadPreprocSettings, 'Enable', 'on');
  251. % Update settings & GUI panels (to enable/disable & unlock):
  252. % Note: Don't redetect CondID / Status yet since GroupID reset.
  253. handles = UpdateSubjIDSettings (handles);
  254. handles = UpdateInputDataSettings (handles);
  255. handles = UpdateEventSettings (handles);
  256. handles = UpdateCondIDSettings (handles);
  257. handles = UpdateStatusSettings (handles);
  258. handles = UpdateEpochSettings (handles);
  259. handles = UpdateBaselineSettings (handles);
  260. handles = UpdateGeneralFilterSettings (handles);
  261. handles = UpdateBandstopFilterSettings (handles);
  262. handles = UpdateDFTFilterSettings (handles);
  263. handles = UpdateMedianFilterSettings (handles);
  264. handles = UpdateDetrendSettings (handles);
  265. handles = UpdateOtherAdvSettings (handles);
  266. % Save handles:
  267. guidata(hObject, handles);
  268. close(WaitBox);
  269. %--- Executes on button press in ButtonLoadDataID. ---%
  270. %-----------------------------------------------------%
  271. function ButtonLoadDataID_Callback(hObject, eventdata, handles)
  272. if isempty(handles.paths.Rootpath)
  273. msgbox('Warning: Select root directory first.', 'Warning:');
  274. return;
  275. end
  276. % Get DataID folders in current rootpath:
  277. DetectedFolders = dir([handles.paths.Rootpath,'/DataID_*']);
  278. DetectedFolders = [DetectedFolders; dir([handles.paths.Rootpath,'/DataID-ICAclean_*'])];
  279. RemoveIndex = [];
  280. for d = 1:length(DetectedFolders)
  281. if DetectedFolders(d).isdir ~= 1
  282. RemoveIndex = [RemoveIndex, d]; % Get unwanted indices
  283. end
  284. end
  285. DetectedFolders(RemoveIndex) = [];
  286. if isempty(DetectedFolders)
  287. msgbox('Error: No DataID folders detected inside root dir.', 'Error:');
  288. return;
  289. end
  290. % List DataID folders for selection:
  291. DetectedFolders = {DetectedFolders.name};
  292. SelectedIndex = listdlg('PromptString', 'Select DataID to load:',...
  293. 'ListSize', [300, 300], 'SelectionMode', 'single', 'ListString', DetectedFolders);
  294. if isempty(SelectedIndex) % If user cancels.
  295. return;
  296. end
  297. SelectedDataID = DetectedFolders{SelectedIndex};
  298. % Check if DataID was ICA cleaned:
  299. if ~strcmp(SelectedDataID(1:7), 'DataID_') && strcmp(SelectedDataID(1:16), 'DataID-ICAclean_')
  300. message = {'IMPORTANT:'; '';
  301. 'ICA-cleaned DataID folders cannot be directly loaded back into';
  302. 'the MEG preprocessing module (PreprocMEG GUI).'; '';
  303. 'If you wish to further preprocess files from DataID-ICAclean folders,';
  304. 'create a new DataID and select the ICA cleaned files from there.'};
  305. msgbox(message)
  306. return;
  307. end
  308. SelectedDataID(1:7) = []; % Remove "DataID_" prefix to get DataID tag.
  309. FullpathDataID = [handles.paths.Rootpath,'/DataID_',SelectedDataID];
  310. % Set as current DataID:
  311. handles.name.DataID = SelectedDataID;
  312. handles.paths.DataID = FullpathDataID;
  313. set(handles.TextboxDataID, 'String', handles.name.DataID);
  314. % Start WaitBox:
  315. WaitBox = StartWaitBox('LOADING DATA ID:');
  316. % Reset GroupID:
  317. handles.name.CurrentGroupID = [];
  318. handles.paths.CurrentGroupID = [];
  319. set(handles.TextboxGroupID, 'String', 'None Selected');
  320. % Reset settings & GUI panels:
  321. handles = ResetSubjIDSettings (handles);
  322. handles = ResetInputDataSettings (handles);
  323. handles = ResetEventSettings (handles);
  324. handles = ResetCondIDSettings (handles);
  325. handles = ResetStatusSettings (handles);
  326. handles = ResetEpochSettings (handles);
  327. handles = ResetBaselineSettings (handles);
  328. handles = ResetGeneralFilterSettings (handles);
  329. handles = ResetBandstopFilterSettings (handles);
  330. handles = ResetDFTFilterSettings (handles);
  331. handles = ResetMedianFilterSettings (handles);
  332. handles = ResetDetrendSettings (handles);
  333. handles = ResetOtherAdvSettings (handles);
  334. handles.gui.LockPreprocSettings = 'off';
  335. set(handles.ButtonSaveLockSettings, 'Enable', 'on');
  336. set(handles.ButtonLoadPreprocSettings, 'Enable', 'on');
  337. % Load PreprocSettings.mat for selected DataID:
  338. % Note: Don't load SubjID / CondID / InputData since GroupID reset.
  339. if exist([FullpathDataID,'/PreprocSettings.mat'], 'file')
  340. LoadedMat = load([FullpathDataID,'/PreprocSettings.mat']);
  341. handles = LoadEpochSettings (handles, LoadedMat);
  342. handles = LoadBaselineSettings (handles, LoadedMat);
  343. handles = LoadGeneralFilterSettings (handles, LoadedMat);
  344. handles = LoadBandstopFilterSettings (handles, LoadedMat);
  345. handles = LoadDFTFilterSettings (handles, LoadedMat);
  346. handles = LoadMedianFilterSettings (handles, LoadedMat);
  347. handles = LoadDetrendSettings (handles, LoadedMat);
  348. handles = LoadOtherAdvSettings (handles, LoadedMat);
  349. handles.gui.LockPreprocSettings = 'on';
  350. set(handles.ButtonSaveLockSettings, 'Enable', 'off');
  351. set(handles.ButtonLoadPreprocSettings, 'Enable', 'off');
  352. else
  353. message = {'WARNING:'; '';
  354. 'PreprocSettings.mat was not found for selected DataID.';
  355. 'Settings will need to be reconfigured from scratch.'; '';
  356. 'If preprocessed data exists for this DataID, take care to match';
  357. 'the same settings used before to avoid mismatch across datasets.'};
  358. msgbox(message, 'WARNING:');
  359. end
  360. % Update settings & GUI panels:
  361. % Note: Don't redetect CondID / Status yet since GroupID reset.
  362. handles = UpdateSubjIDSettings (handles);
  363. handles = UpdateInputDataSettings (handles);
  364. handles = UpdateEventSettings (handles);
  365. handles = UpdateCondIDSettings (handles);
  366. handles = UpdateStatusSettings (handles);
  367. handles = UpdateEpochSettings (handles);
  368. handles = UpdateBaselineSettings (handles);
  369. handles = UpdateGeneralFilterSettings (handles);
  370. handles = UpdateBandstopFilterSettings (handles);
  371. handles = UpdateDFTFilterSettings (handles);
  372. handles = UpdateMedianFilterSettings (handles);
  373. handles = UpdateDetrendSettings (handles);
  374. handles = UpdateOtherAdvSettings (handles);
  375. % Save handles:
  376. guidata(hObject, handles);
  377. close(WaitBox);
  378. %--- Textbox to display current DataID: ---%
  379. %------------------------------------------%
  380. function TextboxDataID_Callback(hObject, eventdata, handles)
  381. EnteredText = get(handles.TextboxDataID, 'String');
  382. if ~isequal(EnteredText, handles.name.DataID)
  383. set(handles.TextboxDataID, 'String', handles.name.DataID);
  384. msgbox('Note: Use button to change DataID.')
  385. end
  386. %============================================%
  387. % FUNCTIONS FOR CREATING OR LOADING GROUPID: %
  388. %============================================%
  389. %--- Executes on button press in ButtonCreateGroupID. ---%
  390. %--------------------------------------------------------%
  391. function ButtonCreateGroupID_Callback(hObject, eventdata, handles)
  392. if isempty(handles.paths.Rootpath)
  393. msgbox('Warning: Select root directory first.', 'Warning:');
  394. return;
  395. end
  396. if isempty(handles.name.DataID) || isempty(handles.paths.DataID)
  397. msgbox('Warning: Create or load DataID first.', 'Warning:');
  398. return;
  399. end
  400. % Enter name of GroupID:
  401. UserInput = inputdlg('Enter GroupID name:', 'Create new GroupID:');
  402. UserInput = deblank(UserInput);
  403. UserInput = regexprep(UserInput, '\s+', '_');
  404. if isempty(char(UserInput))
  405. return; % If user cancels
  406. end
  407. PathInputID = [handles.paths.DataID,'/GroupID_',UserInput{1}];
  408. if exist(PathInputID, 'dir')
  409. msgbox('Error: Specified GroupID already exists for this DataID!', 'Error:')
  410. return;
  411. end
  412. % Set GroupID and create folder:
  413. status = mkdir(PathInputID);
  414. if status == 1 % If mkdir successful
  415. handles.name.CurrentGroupID = UserInput{1};
  416. handles.paths.CurrentGroupID = PathInputID;
  417. set(handles.TextboxGroupID, 'String', handles.name.CurrentGroupID);
  418. else
  419. msgbox('Error: Failed to create GroupID folder.', 'Error:')
  420. return;
  421. end
  422. % Start Waitbox:
  423. WaitBox = StartWaitBox('CREATING GROUP ID:');
  424. % Reset input settings & GUI panels:
  425. handles = ResetSubjIDSettings (handles);
  426. handles = ResetInputDataSettings (handles);
  427. handles = ResetEventSettings (handles);
  428. handles = ResetCondIDSettings (handles);
  429. handles = ResetStatusSettings (handles);
  430. % Update settings & GUI panels:
  431. handles = UpdateSubjIDSettings (handles);
  432. handles = UpdateInputDataSettings (handles);
  433. handles = UpdateEventSettings (handles);
  434. handles = UpdateCondIDSettings (handles);
  435. handles = UpdateStatusSettings (handles);
  436. % Save handles:
  437. guidata(hObject, handles);
  438. close(WaitBox);
  439. %--- Executes on button press in ButtonLoadGroupID. ---%
  440. %------------------------------------------------------%
  441. function ButtonLoadGroupID_Callback(hObject, eventdata, handles)
  442. if isempty(handles.paths.Rootpath)
  443. msgbox('Warning: Select root directory first.', 'Warning:');
  444. return;
  445. end
  446. if isempty(handles.name.DataID) || isempty(handles.paths.DataID)
  447. msgbox('Warning: Create or load DataID first.', 'Warning:');
  448. return;
  449. end
  450. % Acquire GroupID folders for current DataID:
  451. DetectedFolders = dir([handles.paths.DataID,'/GroupID_*']);
  452. RemoveIndex = [];
  453. for g = 1:length(DetectedFolders)
  454. if DetectedFolders(g).isdir ~= 1
  455. RemoveIndex = [RemoveIndex, g]; % Get unwanted indices
  456. end
  457. end
  458. DetectedFolders(RemoveIndex) = [];
  459. if isempty(DetectedFolders)
  460. msgbox('Error: No GroupID folders were detected for current DataID.', 'Error:');
  461. return;
  462. end
  463. % List detected GroupID folders and select desired GroupID:
  464. DetectedFolders = {DetectedFolders.name};
  465. SelectedIndex = listdlg('PromptString', 'Select GroupID to load:',...
  466. 'ListSize', [300, 300], 'SelectionMode', 'single', 'ListString', DetectedFolders);
  467. if isempty(SelectedIndex)
  468. return; % If user cancels
  469. end
  470. SelectedGroupID = DetectedFolders{SelectedIndex};
  471. SelectedGroupID(1:8) = []; % Remove "GroupID_" prefix to get GroupID.
  472. % Set as current GroupID:
  473. handles.name.CurrentGroupID = SelectedGroupID;
  474. handles.paths.CurrentGroupID = [handles.paths.DataID,'/GroupID_',SelectedGroupID];
  475. set(handles.TextboxGroupID, 'String', handles.name.CurrentGroupID);
  476. % Start Waitbox:
  477. WaitBox = StartWaitBox('LOADING GROUP ID:');
  478. % Reset input settings & GUI panels:
  479. handles = ResetSubjIDSettings (handles);
  480. handles = ResetInputDataSettings (handles);
  481. handles = ResetEventSettings (handles);
  482. handles = ResetCondIDSettings (handles);
  483. handles = ResetStatusSettings (handles);
  484. % Load a PreprocInputMEG .mat for GroupID if available:
  485. CheckExist = dir([handles.paths.CurrentGroupID,'/PreprocInputMEG_*.mat']);
  486. if ~isempty(CheckExist)
  487. [matfile, matpath] = uigetfile([handles.paths.CurrentGroupID,...
  488. '/PreprocInputMEG_*.mat'], 'Select PreprocInputMEG .mat:', 'MultiSelect', 'off');
  489. if matfile == 0
  490. message = {'WARNING:'; ''; 'PreprocInputMEG .mat file was not selected.'; '';
  491. 'Subject ID and selected dataset files will not be loaded.';
  492. 'To select a PreprocInputMEG file, push the load button again.'};
  493. msgbox(message, 'Warning:');
  494. else
  495. LoadedMat = load([matpath,matfile]);
  496. handles = LoadSubjIDSettings (handles, LoadedMat);
  497. handles = LoadInputDataSettings (handles, LoadedMat);
  498. end
  499. else
  500. message = {'WARNING:'; '';
  501. 'PreprocInputMEG .mat file(s) were not found in GroupID folder.';
  502. 'SubjID and input datasets will need to be selected again.'};
  503. msgbox(message, 'Warning:');
  504. end
  505. % Redetect Events and CondID folders:
  506. handles = DetectDatasetEvents (handles);
  507. handles = DetectCondIDs (handles);
  508. % Update input settings & GUI panels:
  509. handles = UpdateSubjIDSettings (handles);
  510. handles = UpdateInputDataSettings (handles);
  511. handles = UpdateEventSettings (handles);
  512. handles = UpdateCondIDSettings (handles);
  513. handles = UpdateStatusSettings (handles);
  514. % Save handles:
  515. guidata(hObject, handles);
  516. close(WaitBox);
  517. %--- Textbox to display current GroupID: ---%
  518. %-------------------------------------------%
  519. function TextboxGroupID_Callback(hObject, eventdata, handles)
  520. EnteredText = get(handles.TextboxGroupID, 'String');
  521. if ~isequal(EnteredText, handles.name.CurrentGroupID)
  522. set(handles.TextboxGroupID, 'String', handles.name.CurrentGroupID);
  523. msgbox('Note: Use button to change GroupID.')
  524. end
  525. %============================================%
  526. % FUNCTIONS FOR ADDING OR REMOVING SUBJECTS: %
  527. %============================================%
  528. %--- Executes on selection change in ListboxSubjID. ---%
  529. %------------------------------------------------------%
  530. function ListboxSubjID_Callback(hObject, eventdata, handles)
  531. SelectedIndex = get(handles.ListboxSubjID, 'Value');
  532. set(handles.ListboxInputData, 'Value', SelectedIndex);
  533. set(handles.ListboxStatus, 'Value', SelectedIndex);
  534. %--- User enters subject to add into this textbox. ---%
  535. %-----------------------------------------------------%
  536. function TextboxSubjID_Callback(hObject, eventdata, handles)
  537. keypress = get(gcf,'CurrentCharacter');
  538. if isequal(keypress, char(13))
  539. ButtonAddSubjID_Callback(hObject, eventdata, handles);
  540. end
  541. %--- Executes on button press in ButtonAddSubjID. ---%
  542. %----------------------------------------------------%
  543. function ButtonAddSubjID_Callback(hObject, eventdata, handles)
  544. if isempty(handles.name.DataID) || isempty(handles.paths.DataID)
  545. msgbox('Warning: Create or load DataID.', 'Warning:');
  546. return;
  547. end
  548. if isempty(handles.name.CurrentGroupID)
  549. msgbox('Warning: Create or load GroupID.', 'Warning:');
  550. return;
  551. end
  552. % Reads and set SubjID:
  553. InputSubjID = get(handles.TextboxSubjID, 'String');
  554. InputSubjID = deblank(InputSubjID);
  555. InputSubjID = regexprep(InputSubjID, '\s+', '_');
  556. InputSubjID = cellstr(InputSubjID);
  557. if isempty(InputSubjID{1})
  558. return;
  559. end
  560. if ~isempty(handles.name.SubjID) && ismember(InputSubjID{1}, handles.name.SubjID)
  561. return % If SubjID already added
  562. end
  563. handles.name.SubjID = [handles.name.SubjID; InputSubjID];
  564. NewIndex = length(handles.name.SubjID);
  565. % Initialize data & status cells for new subject:
  566. handles.paths.DataFolder {NewIndex} = [];
  567. handles.paths.DataFile {NewIndex} = [];
  568. handles.paths.DataFullpath {NewIndex} = [];
  569. handles.gui.ReadHdrSuccess {NewIndex} = -1;
  570. handles.gui.DataContinuous {NewIndex} = -1;
  571. handles.gui.InputNumTrials {NewIndex} = -1;
  572. handles.gui.EventInfoExist {NewIndex} = -1;
  573. handles.gui.AllEventInfo {NewIndex} = [];
  574. handles.gui.Status {NewIndex} = [];
  575. % Update input settings & GUI panels:
  576. handles = UpdateSubjIDSettings (handles);
  577. handles = UpdateInputDataSettings (handles);
  578. handles = UpdateStatusSettings (handles);
  579. % Save handles:
  580. set(handles.ListboxSubjID, 'Value', length(handles.name.SubjID));
  581. if ~isempty(handles.paths.DataFullpath)
  582. set(handles.ListboxInputData, 'Value', length(handles.name.SubjID));
  583. end
  584. if ~isempty(handles.gui.Status)
  585. set(handles.ListboxStatus, 'Value', length(handles.name.SubjID));
  586. end
  587. guidata(hObject, handles);
  588. %--- Executes on button press in ButtonRmvSubjID. ---%
  589. %----------------------------------------------------%
  590. function ButtonRmvSubjID_Callback(hObject, eventdata, handles)
  591. if isempty(handles.name.SubjID)
  592. return;
  593. end
  594. SelectedIndex = get(handles.ListboxSubjID, 'Value');
  595. handles.name.SubjID(SelectedIndex) = [];
  596. % Remove data & status cells for removed subject:
  597. handles.paths.DataFolder (SelectedIndex) = [];
  598. handles.paths.DataFile (SelectedIndex) = [];
  599. handles.paths.DataFullpath (SelectedIndex) = [];
  600. handles.gui.ReadHdrSuccess (SelectedIndex) = [];
  601. handles.gui.DataContinuous (SelectedIndex) = [];
  602. handles.gui.InputNumTrials (SelectedIndex) = [];
  603. handles.gui.EventInfoExist (SelectedIndex) = [];
  604. handles.gui.AllEventInfo (SelectedIndex) = [];
  605. handles.gui.Status (SelectedIndex) = [];
  606. % Update input settings & GUI panels:
  607. handles = UpdateSubjIDSettings (handles);
  608. handles = UpdateInputDataSettings (handles);
  609. handles = UpdateStatusSettings (handles);
  610. % Save handles:
  611. guidata(hObject, handles);
  612. %--- Updates SubjID settings & GUI panel: ---%
  613. %--------------------------------------------%
  614. function OutputHandles = UpdateSubjIDSettings(InputHandles)
  615. handles = InputHandles;
  616. % Update listbox:
  617. set(handles.ListboxSubjID, 'String', handles.name.SubjID);
  618. CurrentIndex = get(handles.ListboxSubjID, 'Value');
  619. MaxSubjIndex = length(handles.name.SubjID);
  620. if isempty(CurrentIndex) || CurrentIndex == 0 || CurrentIndex > MaxSubjIndex
  621. set(handles.ListboxSubjID, 'Value', MaxSubjIndex);
  622. set(handles.ListboxInputData, 'Value', MaxSubjIndex);
  623. set(handles.ListboxStatus, 'Value', MaxSubjIndex);
  624. end
  625. % Set output handles:
  626. OutputHandles = handles;
  627. %--- Load SubjID settings & GUI panel: ---%
  628. %-----------------------------------------%
  629. function OutputHandles = LoadSubjIDSettings(InputHandles, LoadedMat)
  630. handles = InputHandles;
  631. handles.name.SubjID = LoadedMat.name.SubjID;
  632. set(handles.ListboxSubjID, 'String', handles.name.SubjID);
  633. set(handles.ListboxSubjID, 'Value', 1);
  634. % Set output handles:
  635. OutputHandles = handles;
  636. %--- Reset SubjID settings & GUI panel: ---%
  637. %------------------------------------------%
  638. function OutputHandles = ResetSubjIDSettings(InputHandles)
  639. handles = InputHandles;
  640. handles.name.SubjID = [];
  641. set(handles.ListboxSubjID, 'String', []);
  642. set(handles.ListboxSubjID, 'Value', 1);
  643. % Set output handles:
  644. OutputHandles = handles;
  645. %=========================================%
  646. % FUNCTIONS FOR ADDING/REMOVING DATASETS: %
  647. %=========================================%
  648. %--- Executes on selection change in DropdownDataFiletype. ---%
  649. %------------------------------------------------------------------%
  650. function DropdownDataFiletype_Callback(hObject, eventdata, handles)
  651. if isempty(handles.name.DataID) || isempty(handles.paths.DataID)
  652. msgbox('Warning: Create or load DataID first.', 'Warning:');
  653. return;
  654. end
  655. if isempty(handles.name.CurrentGroupID)
  656. msgbox('Warning: Create or load a GroupID first.', 'Warning:');
  657. return;
  658. end
  659. if ~isempty(handles.paths.DataFullpath)
  660. prompt = {'WARNING:'; '';
  661. 'Changing filetype will clear selected datasets.'; '';
  662. 'Do you wish to continue?'};
  663. ChangeType = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'NO');
  664. if strcmp(ChangeType, 'NO')
  665. return;
  666. end
  667. end
  668. % Clear and update input data:
  669. % Note: Don't ResetInputData since it will cancel dropdown selection.
  670. handles.paths.DataFolder = [];
  671. handles.paths.DataFile = [];
  672. handles.paths.DataFullpath = [];
  673. handles.gui.ReadHdrSuccess = [];
  674. handles.gui.DataContinuous = [];
  675. handles.gui.InputNumTrials = [];
  676. handles.gui.EventInfoExist = [];
  677. handles.gui.AllEventInfo = [];
  678. handles.gui.Status = [];
  679. for s = 1:length(handles.name.SubjID) % Reinitialize
  680. handles.paths.DataFolder{s} = [];
  681. handles.paths.DataFile{s} = [];
  682. handles.paths.DataFullpath{s} = [];
  683. handles.gui.ReadHdrSuccess{s} = -1;
  684. handles.gui.DataContinuous{s} = -1;
  685. handles.gui.InputNumTrials{s} = -1;
  686. handles.gui.EventInfoExist{s} = -1;
  687. handles.gui.AllEventInfo{s} = [];
  688. handles.gui.Status{s} = [];
  689. end
  690. handles = ResetEventSettings (handles);
  691. handles = ResetStatusSettings (handles);
  692. % Update settings & GUI panels:
  693. handles = UpdateInputDataSettings (handles);
  694. handles = UpdateEventSettings (handles);
  695. handles = UpdateStatusSettings (handles);
  696. handles = UpdateEpochSettings (handles);
  697. handles = UpdateOtherAdvSettings (handles);
  698. % Display warning for fieldtrip filetype:
  699. if strcmp(handles.gui.DataFiletype, 'Fieldtrip')
  700. message = {'WARNING:'; '';
  701. 'Selecting for files that have already been preprocessed into FT format.';
  702. 'It is up to user to keep track of what options have already been applied.';
  703. 'If you are unsure, start with raw format to avoid complications.'};
  704. msgbox(message, 'WARNING');
  705. end
  706. % Save handles:
  707. guidata(hObject, handles);
  708. %--- Executes on selection change in ListboxInputData. ---%
  709. %---------------------------------------------------------%
  710. function ListboxInputData_Callback(hObject, eventdata, handles)
  711. SelectedIndex = get(handles.ListboxInputData, 'Value');
  712. set(handles.ListboxSubjID, 'Value', SelectedIndex);
  713. set(handles.ListboxStatus, 'Value', SelectedIndex);
  714. %--- Executes on button press in CheckboxShowDataFullpath. ---%
  715. %-------------------------------------------------------------%
  716. function CheckboxShowDataFullpath_Callback(hObject, eventdata, handles)
  717. handles = UpdateInputDataSettings(handles);
  718. guidata(hObject, handles);
  719. %--- Executes on button press in ButtonAddInputData. ---%
  720. %-----------------------------------------------------%
  721. function ButtonAddInputData_Callback(hObject, eventdata, handles)
  722. if isempty(handles.name.DataID) || isempty(handles.paths.DataID)
  723. msgbox('Warning: Create or load DataID first.', 'Warning:');
  724. return;
  725. end
  726. if isempty(handles.name.CurrentGroupID)
  727. msgbox('Warning: Create or load a GroupID first.', 'Warning:');
  728. return;
  729. end
  730. if isempty(handles.name.SubjID)
  731. msgbox('Warning: Add SubjectID''s first.', 'Warning:');
  732. return;
  733. end
  734. % Use "uipickfiles" (Douglas M. Schwarz, 2007) to select datasets:
  735. switch handles.gui.DataFiletype
  736. case 'CTFds'
  737. SelectedFiles = uipickfiles('FilterSpec', [handles.paths.Rootpath,'/*.ds'],...
  738. 'REfilter', '.ds$', 'REdirs', 0);
  739. case 'Other'
  740. SelectedFiles = uipickfiles('FilterSpec', handles.paths.Rootpath);
  741. case 'Fieldtrip'
  742. SelectedFiles = uipickfiles('FilterSpec', [handles.paths.Rootpath,'/*.mat'],...
  743. 'REfilter', '.mat$');
  744. end
  745. if ~iscell(SelectedFiles) && SelectedFiles == 0
  746. return; % If user cancels
  747. end
  748. % For each file, match to SubjID and perform checks:
  749. WrongFormat = {};
  750. MatchFailed = {};
  751. DataWaitbar = waitbar(0, ...
  752. 'Please wait. Scanning selected datasets:', 'Windowstyle', 'modal');
  753. for f = 1:length(SelectedFiles)
  754. waitbar(f/length(SelectedFiles), DataWaitbar);
  755. [Folder, File, Ext] = fileparts(SelectedFiles{f});
  756. % Check if selected file format is valid:
  757. if strcmp(handles.gui.DataFiletype, 'CTFds') && ~strcmp(Ext, '.ds')
  758. WrongFormat = [WrongFormat; SelectedFiles{f}];
  759. continue;
  760. end
  761. if strcmp(handles.gui.DataFiletype, 'Fieldtrip') && ~strcmp(Ext, '.mat')
  762. WrongFormat = [WrongFormat; SelectedFiles{f}];
  763. continue;
  764. end
  765. if strcmp(handles.gui.DataFiletype, 'Other') &&...
  766. (strcmp(Ext, '.ds') || strcmp(Ext, '.mat'))
  767. WrongFormat = [WrongFormat; SelectedFiles{f}];
  768. continue;
  769. end
  770. % Check filename for SubjID match:
  771. % Find SubjID indices that matched.
  772. SubjMatch = regexp([File,Ext], handles.name.SubjID);
  773. SubjIndex = find(~cellfun(@isempty, SubjMatch));
  774. if length(SubjIndex) > 1 % If multiple matches, try to isolate SubjID.
  775. SubjMatch = regexp([File,Ext], strcat(handles.name.SubjID, '_'));
  776. SubjIndex = find(~cellfun(@isempty, SubjMatch));
  777. end
  778. if isempty(SubjIndex) || length(SubjIndex) > 1 % Files failing to match.
  779. MatchFailed = [MatchFailed; SelectedFiles{f}];
  780. end
  781. % Adds dataset for matching SubjID:
  782. if length(SubjIndex) == 1
  783. handles.paths.DataFolder {SubjIndex} = Folder;
  784. handles.paths.DataFile {SubjIndex} = [File,Ext];
  785. handles.paths.DataFullpath {SubjIndex} = SelectedFiles{f};
  786. handles.gui.Status {SubjIndex} = [];
  787. % Check dataset info:
  788. handles = CompileInputDataInfo(handles, SubjIndex);
  789. end
  790. end % SelectedFiles
  791. delete(DataWaitbar);
  792. % Display warning for files with errors:
  793. if ~isempty(WrongFormat)
  794. prompt = {'WARNING:'; '';
  795. 'The following file(s) were not of the correct filetype:'; ''};
  796. prompt = [prompt; WrongFormat];
  797. msgbox(prompt, 'Warning:');
  798. end
  799. if ~isempty(MatchFailed)
  800. prompt = {'WARNING:'; '';
  801. 'The following file(s) could not be matched to a SubjID (Check naming).';
  802. 'To manually add a file for SubjID, use the Force Select button.'; ''};
  803. prompt = [prompt; MatchFailed];
  804. msgbox(prompt, 'Warning:');
  805. end
  806. % Update input settings & GUI panels:
  807. handles = UpdateInputDataSettings (handles);
  808. handles = UpdateEventSettings (handles);
  809. % Detect status of newly selected input data:
  810. set(handles.CheckboxShowOutputStatus, 'Value', 0);
  811. handles = DetectStatus (handles);
  812. handles = UpdateStatusSettings (handles);
  813. % Save handles:
  814. guidata(hObject, handles);
  815. %--- Executes on button press in ButtonForceAddData. ---%
  816. %-----------------------------------------------------%
  817. function ButtonForceAddData_Callback(hObject, eventdata, handles)
  818. if isempty(handles.name.DataID) || isempty(handles.paths.DataID)
  819. msgbox('Warning: Create or load DataID first.', 'Warning:');
  820. return;
  821. end
  822. if isempty(handles.name.CurrentGroupID)
  823. msgbox('Warning: Create or load a GroupID first.', 'Warning:');
  824. return;
  825. end
  826. if isempty(handles.name.SubjID)
  827. msgbox('Warning: Add SubjectID''s first.', 'Warning:');
  828. return;
  829. end
  830. % Use "uipickfiles" (Douglas M. Schwarz, 2007) to select dataset:
  831. switch handles.gui.DataFiletype
  832. case 'CTFds'
  833. SelectedFile = uipickfiles('FilterSpec', [handles.paths.Rootpath,'/*.ds'],...
  834. 'NumFiles', 1, 'Output', 'char', 'REfilter', '.ds$', 'REdirs', 1);
  835. case 'Other'
  836. SelectedFile = uipickfiles('FilterSpec', handles.paths.Rootpath,...
  837. 'NumFiles', 1, 'Output', 'char');
  838. case 'Fieldtrip'
  839. SelectedFile = uipickfiles('FilterSpec', [handles.paths.Rootpath,'/*.mat'],...
  840. 'NumFiles', 1, 'Output', 'char', 'REfilter', '.mat$');
  841. end
  842. if SelectedFile == 0
  843. return; % If user cancels
  844. end
  845. [Folder, File, Ext] = fileparts(SelectedFile);
  846. SelectedIndex = get(handles.ListboxSubjID, 'Value');
  847. % Check if selected file format is valid:
  848. if strcmp(handles.gui.DataFiletype, 'CTFds') && ~strcmp(Ext, '.ds')
  849. msgbox('Error: Selected file should be CTF .ds format.', 'Error:')
  850. return;
  851. end
  852. if strcmp(handles.gui.DataFiletype, 'Fieldtrip') && ~strcmp(Ext, '.mat')
  853. msgbox('Error: Selected file should be Fieldtrip .mat.', 'Error:')
  854. return;
  855. end
  856. if strcmp(handles.gui.DataFiletype, 'Other') &&...
  857. (strcmp(Ext, '.ds') || strcmp(Ext, '.mat'))
  858. msgbox('Error: Selected file was incorrect filetype.', 'Error:')
  859. return;
  860. end
  861. % Add as input dataset for currently selected subject:
  862. handles.paths.DataFolder {SelectedIndex} = Folder;
  863. handles.paths.DataFile {SelectedIndex} = [File,Ext];
  864. handles.paths.DataFullpath {SelectedIndex} = SelectedFile;
  865. handles.gui.Status {SelectedIndex} = [];
  866. % Check dataset info:
  867. handles = CompileInputDataInfo(handles, SelectedIndex);
  868. % Update input settings & GUI panels:
  869. handles = UpdateInputDataSettings (handles);
  870. handles = UpdateEventSettings (handles); % Let user choose when to detect status here.
  871. handles = UpdateStatusSettings (handles); % Don't status detect for single selects.
  872. % Save handles:
  873. guidata(hObject, handles);
  874. %--- Executes on button press in ButtonRmvInputData. ---%
  875. %-----------------------------------------------------%
  876. function ButtonRmvInputData_Callback(hObject, eventdata, handles)
  877. if isempty(handles.paths.DataFile)
  878. return;
  879. end
  880. % Clear dataset for selected subject:
  881. SelectedIndex = get(handles.ListboxInputData, 'Value');
  882. handles.paths.DataFolder {SelectedIndex} = [];
  883. handles.paths.DataFile {SelectedIndex} = [];
  884. handles.paths.DataFullpath {SelectedIndex} = [];
  885. handles.gui.ReadHdrSuccess {SelectedIndex} = -1;
  886. handles.gui.DataContinuous {SelectedIndex} = -1;
  887. handles.gui.InputNumTrials {SelectedIndex} = -1;
  888. handles.gui.EventInfoExist {SelectedIndex} = -1;
  889. handles.gui.AllEventInfo {SelectedIndex} = [];
  890. handles.gui.Status {SelectedIndex} = [];
  891. % Update input settings & GUI panels:
  892. handles = UpdateInputDataSettings (handles);
  893. handles = UpdateEventSettings (handles);
  894. handles = UpdateStatusSettings (handles);
  895. % Save handles:
  896. guidata(hObject, handles);
  897. %--- Check and compile info for input datasets: ---%
  898. %--------------------------------------------------%
  899. function OutputHandles = CompileInputDataInfo(InputHandles, SubjIndex)
  900. handles = InputHandles;
  901. % Checks dataset hdr, events, and continuous / epoched:
  902. if ~strcmp(handles.gui.DataFiletype, 'Fieldtrip')
  903. try
  904. Hdr = [];
  905. Hdr = ft_read_header(handles.paths.DataFullpath{SubjIndex});
  906. handles.gui.ReadHdrSuccess{SubjIndex} = 1;
  907. if Hdr.nTrials == 1
  908. handles.gui.DataContinuous{SubjIndex} = 1;
  909. handles.gui.InputNumTrials{SubjIndex} = 1;
  910. else
  911. handles.gui.DataContinuous{SubjIndex} = 0;
  912. handles.gui.InputNumTrials{SubjIndex} = Hdr.nTrials;
  913. end
  914. catch
  915. handles.gui.ReadHdrSuccess{SubjIndex} = 0;
  916. handles.gui.DataContinuous{SubjIndex} = -1; % No Hdr
  917. handles.gui.InputNumTrials{SubjIndex} = -1;
  918. end
  919. Events = [];
  920. Events = ft_read_event(handles.paths.DataFullpath{SubjIndex});
  921. if isempty(Events)
  922. handles.gui.EventInfoExist{SubjIndex} = 0;
  923. handles.gui.AllEventInfo {SubjIndex} = [];
  924. else
  925. handles.gui.EventInfoExist{SubjIndex} = 1;
  926. handles.gui.AllEventInfo {SubjIndex} = Events;
  927. end
  928. elseif strcmp(handles.gui.DataFiletype, 'Fieldtrip')
  929. LoadData = [];
  930. LoadData = LoadFTmat(handles.paths.DataFullpath{SubjIndex}, 'PreprocMEG');
  931. if ~isempty(LoadData) && isfield(LoadData, 'hdr')
  932. NumTrials = length(LoadData.trial);
  933. handles.gui.ReadHdrSuccess{SubjIndex} = 1;
  934. if NumTrials == 1
  935. handles.gui.DataContinuous{SubjIndex} = 1;
  936. handles.gui.InputNumTrials{SubjIndex} = 1;
  937. else
  938. handles.gui.DataContinuous{SubjIndex} = 0;
  939. handles.gui.InputNumTrials{SubjIndex} = NumTrials;
  940. end
  941. else
  942. handles.gui.ReadHdrSuccess{SubjIndex} = 0;
  943. handles.gui.DataContinuous{SubjIndex} = -1; % No Hdr
  944. handles.gui.InputNumTrials{SubjIndex} = -1;
  945. end
  946. if ~isempty(LoadData) && isfield(LoadData, 'AllEventInfo')
  947. handles.gui.EventInfoExist{SubjIndex} = 1;
  948. handles.gui.AllEventInfo {SubjIndex} = LoadData.AllEventInfo;
  949. else
  950. handles.gui.EventInfoExist{SubjIndex} = 0;
  951. handles.gui.AllEventInfo {SubjIndex} = [];
  952. end
  953. end
  954. % Set output handles:
  955. OutputHandles = handles;
  956. %--- Updates data settings & GUI panel: ---%
  957. %------------------------------------------%
  958. function OutputHandles = UpdateInputDataSettings(InputHandles)
  959. handles = InputHandles;
  960. % Make sure cells initialized:
  961. for s = 1:length(handles.name.SubjID)
  962. try
  963. handles.paths.DataFolder{s};
  964. handles.paths.DataFile{s};
  965. handles.paths.DataFullpath{s};
  966. handles.gui.ReadHdrSuccess{s};
  967. handles.gui.DataContinuous{s};
  968. handles.gui.InputNumTrials{s};
  969. handles.gui.EventInfoExist{s};
  970. handles.gui.AllEventInfo{s};
  971. catch
  972. handles.paths.DataFolder{s} = [];
  973. handles.paths.DataFile{s} = [];
  974. handles.paths.DataFullpath{s} = [];
  975. handles.gui.ReadHdrSuccess{s} = -1;
  976. handles.gui.DataContinuous{s} = -1;
  977. handles.gui.InputNumTrials{s} = -1;
  978. handles.gui.EventInfoExist{s} = -1;
  979. handles.gui.AllEventInfo{s} = [];
  980. end
  981. end
  982. % Update input data settings:
  983. DropdownOptions = get(handles.DropdownDataFiletype, 'String');
  984. DataFiletype = DropdownOptions{get(handles.DropdownDataFiletype, 'Value')};
  985. switch DataFiletype
  986. case 'CTF .ds'
  987. handles.gui.DataFiletype = 'CTFds';
  988. case 'Other Format'
  989. handles.gui.DataFiletype = 'Other';
  990. case 'Fieldtrip .mat'
  991. handles.gui.DataFiletype = 'Fieldtrip';
  992. otherwise
  993. error('Unrecognized Option'); % error-check
  994. end
  995. % Update listbox:
  996. if get(handles.CheckboxShowDataFullpath, 'Value') == 1
  997. set(handles.ListboxInputData, 'String', handles.paths.DataFullpath);
  998. else
  999. set(handles.ListboxInputData, 'String', handles.paths.DataFile);
  1000. end
  1001. % Enable/Disable GUI components:
  1002. if strcmp(handles.gui.LockPreprocSettings, 'off')
  1003. set(handles.DropdownDataFiletype, 'Enable', 'on');
  1004. else
  1005. set(handles.DropdownDataFiletype, 'Enable', 'off');
  1006. end
  1007. % Set output handles:
  1008. OutputHandles = handles;
  1009. %--- Load data settings & GUI panel: ---%
  1010. %---------------------------------------%
  1011. function OutputHandles = LoadInputDataSettings(InputHandles, LoadedMat)
  1012. handles = InputHandles;
  1013. % Load input data:
  1014. handles.paths.DataFolder = LoadedMat.paths.DataFolder;
  1015. handles.paths.DataFile = LoadedMat.paths.DataFile;
  1016. handles.paths.DataFullpath = LoadedMat.paths.DataFullpath;
  1017. handles.gui.DataFiletype = LoadedMat.gui.DataFiletype;
  1018. % Ask user if they wish to refresh dataset info:
  1019. prompt = {'RECHECK & RECOMPILE INFO FOR INPUT DATASETS BEING LOADED?'; '';
  1020. ['NOTE: Only required if the input datasets being loaded have been modified '...
  1021. 'or replaced after their selection in previous sessions.']; '';
  1022. ['If the input datasets have not been altered since the time they were first '...
  1023. 'loaded, this verification step can be skipped to save time.']};
  1024. RecheckData = questdlg(prompt, 'RECHECK DATA?', 'YES', 'NO', 'NO');
  1025. % Refresh or load dataset info:
  1026. if strcmp(RecheckData, 'YES') % Recompile info
  1027. CheckWaitbar = waitbar(0, ...
  1028. 'Please wait. Checking datasets being loaded:', 'Windowstyle', 'modal');
  1029. for s = 1:length(handles.name.SubjID)
  1030. waitbar(s/length(handles.name.SubjID), CheckWaitbar);
  1031. handles = CompileInputDataInfo(handles, s);
  1032. end
  1033. delete(CheckWaitbar);
  1034. else
  1035. handles.gui.ReadHdrSuccess = LoadedMat.gui.ReadHdrSuccess;
  1036. handles.gui.DataContinuous = LoadedMat.gui.DataContinuous;
  1037. handles.gui.InputNumTrials = LoadedMat.gui.InputNumTrials;
  1038. handles.gui.EventInfoExist = LoadedMat.gui.EventInfoExist;
  1039. handles.gui.AllEventInfo = LoadedMat.gui.AllEventInfo;
  1040. end
  1041. % Update GUI:
  1042. set(handles.CheckboxShowDataFullpath, 'Value', 0);
  1043. set(handles.ListboxInputData, 'String', handles.paths.DataFile);
  1044. set(handles.ListboxInputData, 'Value', 1);
  1045. switch handles.gui.DataFiletype
  1046. case 'CTFds'
  1047. DataFiletype = 'CTF .ds';
  1048. case 'Other'
  1049. DataFiletype = 'Other Format';
  1050. case 'Fieldtrip'
  1051. DataFiletype = 'Fieldtrip .mat';
  1052. end
  1053. DropdownOptions = get(handles.DropdownDataFiletype, 'String');
  1054. DropdownValue = find(strcmp(DropdownOptions, DataFiletype));
  1055. set(handles.DropdownDataFiletype, 'Value', DropdownValue);
  1056. if DropdownValue == 0
  1057. error('Option does not exist in dropdown list.') % error-check
  1058. end
  1059. % Set output handles:
  1060. OutputHandles = handles;
  1061. %--- Reset data settings & GUI panel: ---%
  1062. %----------------------------------------%
  1063. function OutputHandles = ResetInputDataSettings(InputHandles)
  1064. handles = InputHandles;
  1065. % Reset input data settings:
  1066. handles.paths.DataFolder = [];
  1067. handles.paths.DataFile = [];
  1068. handles.paths.DataFullpath = [];
  1069. handles.gui.ReadHdrSuccess = [];
  1070. handles.gui.DataContinuous = [];
  1071. handles.gui.InputNumTrials = [];
  1072. handles.gui.EventInfoExist = [];
  1073. handles.gui.AllEventInfo = [];
  1074. for s = 1:length(handles.name.SubjID)
  1075. handles.paths.DataFolder{s} = [];
  1076. handles.paths.DataFile{s} = [];
  1077. handles.paths.DataFullpath{s} = [];
  1078. handles.gui.ReadHdrSuccess{s} = -1;
  1079. handles.gui.DataContinuous{s} = -1;
  1080. handles.gui.InputNumTrials{s} = -1;
  1081. handles.gui.EventInfoExist{s} = -1;
  1082. handles.gui.AllEventInfo{s} = [];
  1083. end
  1084. handles.gui.DataFiletype = 'CTFds';
  1085. % Reset GUI data panel:
  1086. set(handles.CheckboxShowDataFullpath, 'Value', 0);
  1087. set(handles.ListboxInputData, 'String', handles.paths.DataFile);
  1088. set(handles.ListboxInputData, 'Value', 1);
  1089. set(handles.DropdownDataFiletype, 'Value', 1);
  1090. % Set output handles:
  1091. OutputHandles = handles;
  1092. %=========================================%
  1093. % FUNCTIONS FOR SPECIFYING EPOCH-MARKERS: %
  1094. %=========================================%
  1095. %--- Listbox Functions: ---%
  1096. %--------------------------%
  1097. % --- Executes on selection change in ListboxDetectedEvents.
  1098. function ListboxDetectedEvents_Callback(hObject, eventdata, handles)
  1099. % --- Executes on selection change in ListboxTargetMarkers.
  1100. function ListboxTargetMarkers_Callback(hObject, eventdata, handles)
  1101. % --- Executes on selection change in ListboxIncludedEvents.
  1102. function ListboxIncludedEvents_Callback(hObject, eventdata, handles)
  1103. % --- Executes on selection change in ListboxExcludedEvents.
  1104. function ListboxExcludedEvents_Callback(hObject, eventdata, handles)
  1105. %--- Executes on button press in ButtonDetectEvents. ---%
  1106. %-------------------------------------------------------%
  1107. function ButtonDetectEvents_Callback(hObject, eventdata, handles)
  1108. handles = DetectDatasetEvents (handles);
  1109. handles = UpdateEventSettings (handles);
  1110. handles = UpdateStatusSettings (handles);
  1111. guidata(hObject, handles);
  1112. %--- Executes on button press in ButtonAddMarker. ---%
  1113. %----------------------------------------------------%
  1114. function ButtonAddMarker_Callback(hObject, eventdata, handles)
  1115. if isempty(handles.gui.DetectedEvents)
  1116. return;
  1117. end
  1118. % Adds selected event as target marker:
  1119. SelectedEvents = get(handles.ListboxDetectedEvents, 'Value');
  1120. for e = SelectedEvents
  1121. EventValueString = handles.gui.DetectedEvents(e,3);
  1122. if ~isempty(handles.epoch.TargetMarkers) && ...
  1123. ismember(EventValueString, handles.epoch.TargetMarkers(:,3))
  1124. continue; % already added
  1125. end
  1126. handles.epoch.TargetMarkers = ...
  1127. [handles.epoch.TargetMarkers; handles.gui.DetectedEvents(e,:)];
  1128. end
  1129. % Save handles:
  1130. handles = UpdateEventSettings(handles);
  1131. guidata(hObject, handles);
  1132. %--- Executes on button press in ButtonIncludeEvent. ---%
  1133. %-------------------------------------------------------%
  1134. function ButtonIncludeEvent_Callback(hObject, eventdata, handles)
  1135. if isempty(handles.gui.DetectedEvents)
  1136. return;
  1137. end
  1138. % Adds selected event to include (similar to "newDs IncludeEvent"):
  1139. SelectedEvents = get(handles.ListboxDetectedEvents, 'Value');
  1140. for e = SelectedEvents
  1141. EventValueString = handles.gui.DetectedEvents(e,3);
  1142. if ~isempty(handles.epoch.TargetMarkers) && ...
  1143. ismember(EventValueString, handles.epoch.TargetMarkers(:,3))
  1144. msgbox('Error: This event has already been set as target marker.')
  1145. continue;
  1146. end
  1147. if ~isempty(handles.epoch.ExcludedEvents) && ...
  1148. ismember(EventValueString, handles.epoch.ExcludedEvents(:,3))
  1149. msgbox('Error: Cannot set same event to be both included and excluded.')
  1150. continue;
  1151. end
  1152. if ~isempty(handles.epoch.IncludedEvents) && ...
  1153. ismember(EventValueString, handles.epoch.IncludedEvents(:,3))
  1154. continue; % already added
  1155. end
  1156. handles.epoch.IncludedEvents = ...
  1157. [handles.epoch.IncludedEvents; handles.gui.DetectedEvents(e,:)];
  1158. end
  1159. % Save handles:
  1160. handles = UpdateEventSettings(handles);
  1161. guidata(hObject, handles);
  1162. %--- Executes on button press in ButtonExcludeEvent. ---%
  1163. %-------------------------------------------------------%
  1164. function ButtonExcludeEvent_Callback(hObject, eventdata, handles)
  1165. if isempty(handles.gui.DetectedEvents)
  1166. return;
  1167. end
  1168. % Adds selected event to include (similar to "newDs IncludeEvent"):
  1169. SelectedEvents = get(handles.ListboxDetectedEvents, 'Value');
  1170. for e = SelectedEvents
  1171. EventValueString = handles.gui.DetectedEvents(e,3);
  1172. if ~isempty(handles.epoch.TargetMarkers) && ...
  1173. ismember(EventValueString, handles.epoch.TargetMarkers(:,3))
  1174. msgbox('Error: This event has already been set as target marker.')
  1175. continue;
  1176. end
  1177. if ~isempty(handles.epoch.IncludedEvents) && ...
  1178. ismember(EventValueString, handles.epoch.IncludedEvents(:,3))
  1179. msgbox('Error: Cannot set same event to be both excluded and included.')
  1180. continue;
  1181. end
  1182. if ~isempty(handles.epoch.ExcludedEvents) && ...
  1183. ismember(EventValueString, handles.epoch.ExcludedEvents(:,3))
  1184. continue; % already added
  1185. end
  1186. handles.epoch.ExcludedEvents = ...
  1187. [handles.epoch.ExcludedEvents; handles.gui.DetectedEvents(e,:)];
  1188. end
  1189. % Save handles:
  1190. handles = UpdateEventSettings(handles);
  1191. guidata(hObject, handles);
  1192. %--- Executes on button press in ButtonResetEvents. ---%
  1193. %------------------------------------------------------%
  1194. function ButtonResetEvents_Callback(hObject, eventdata, handles)
  1195. % Reset selected events:
  1196. handles.epoch.TargetMarkers = [];
  1197. handles.epoch.IncludedEvents = [];
  1198. handles.epoch.ExcludedEvents = [];
  1199. % Save handles:
  1200. handles = UpdateEventSettings(handles);
  1201. guidata(hObject, handles);
  1202. %--- Scans input datasets for detected events or markers: ---%
  1203. %------------------------------------------------------------%
  1204. function OutputHandles = DetectDatasetEvents(InputHandles)
  1205. handles = InputHandles;
  1206. % Scan available events (markers or triggers) for each selected dataset:
  1207. % Compile event data into matrix: y1 = event-name, y2 = event-value, y3 = eventvaluestring.
  1208. EventsWaitbar = waitbar(0,...
  1209. 'Please wait. Compiling events from datasets:', 'Windowstyle', 'modal');
  1210. handles.gui.DetectedEvents = [];
  1211. for s = 1:length(handles.name.SubjID)
  1212. waitbar(s/length(handles.name.SubjID), EventsWaitbar);
  1213. % Skip subject if dataset not selected or DNE:
  1214. if isempty(handles.paths.DataFile{s})
  1215. continue;
  1216. end
  1217. if ~exist(handles.paths.DataFullpath{s}, 'file')
  1218. StatusMsg = 'Error: Dataset could not be found. Reselect dataset.';
  1219. handles.gui.Status{s} = StatusMsg;
  1220. continue;
  1221. end
  1222. % Get all events in dataset:
  1223. AllEventInfo = handles.gui.AllEventInfo{s};
  1224. if isempty(AllEventInfo) && handles.gui.EventInfoExist{s} == 0
  1225. if ~strcmp(handles.gui.DataFiletype, 'Fieldtrip')
  1226. StatusMsg = 'Error: Events could not be read from selected dataset.';
  1227. else
  1228. StatusMsg = 'Error: AllEventInfo field not found in dataset.';
  1229. end
  1230. handles.gui.Status{s} = StatusMsg;
  1231. continue;
  1232. end
  1233. % For each event-type, acquire all unique trigger-values:
  1234. UniqueEvents = unique({AllEventInfo.type});
  1235. for e = 1:length(UniqueEvents)
  1236. EventType = UniqueEvents{e};
  1237. EventIndices = find(strcmp(EventType, {AllEventInfo.type})); % All indices for event.
  1238. EventValues = unique([AllEventInfo(EventIndices).value]); % Unique values for event.
  1239. % If event does not code for multiple triggers, simply add event:
  1240. if isempty(EventValues)
  1241. if isempty(handles.gui.DetectedEvents) ||...
  1242. ~ismember(EventType, handles.gui.DetectedEvents(:,1))
  1243. NewIndex = size(handles.gui.DetectedEvents, 1) + 1;
  1244. handles.gui.DetectedEvents{NewIndex,1} = EventType;
  1245. handles.gui.DetectedEvents{NewIndex,2} = [];
  1246. handles.gui.DetectedEvents{NewIndex,3} = EventType;
  1247. end
  1248. % If the event codes for multiple triggers, add each trigger:
  1249. else
  1250. for v = 1:length(EventValues)
  1251. EventValueString = [EventType,': ',num2str(EventValues(v))];
  1252. if isempty(handles.gui.DetectedEvents) ||...
  1253. ~ismember(EventValueString, handles.gui.DetectedEvents(:,3))
  1254. NewIndex = size(handles.gui.DetectedEvents, 1) + 1;
  1255. handles.gui.DetectedEvents{NewIndex,1} = EventType;
  1256. handles.gui.DetectedEvents{NewIndex,2} = EventValues(v);
  1257. handles.gui.DetectedEvents{NewIndex,3} = EventValueString;
  1258. end
  1259. end
  1260. end
  1261. end % Events
  1262. end % Subj
  1263. delete(EventsWaitbar);
  1264. % Sort list:
  1265. if ~isempty(handles.gui.DetectedEvents)
  1266. handles.gui.DetectedEvents = sortrows(handles.gui.DetectedEvents, 3);
  1267. end
  1268. % Save as output:
  1269. OutputHandles = handles;
  1270. %--- Update event settings & GUI panel: ---%
  1271. %------------------------------------------%
  1272. function OutputHandles = UpdateEventSettings(InputHandles)
  1273. handles = InputHandles;
  1274. DataContinuous = handles.gui.DataContinuous;
  1275. EventInfoExist = handles.gui.EventInfoExist;
  1276. % If raw datasets selected, check if they are continuous.
  1277. % If epoched datasets have been selected, disable T=0 event selection.
  1278. if ~strcmp(handles.gui.DataFiletype, 'Fieldtrip')
  1279. if ~isempty(DataContinuous) && max(cellfun(@(x) x==0, DataContinuous)) == 1 % If non-continuous
  1280. if strcmp(get(handles.ListboxTargetMarkers, 'Enable'), 'on')
  1281. message = {'WARNING:'; ''; % Only warns if transitioning from enabled to disabled.
  1282. 'Some of the selected datasets has already been epoched (not continuous).'; '';
  1283. 'Target T=0 Events for epoching can only be set for continuous datasets.';
  1284. 'To specify T=0 events, unselect the epoched datasets (see status box).'};
  1285. msgbox(message);
  1286. end
  1287. handles.epoch.TargetMarkers = [];
  1288. set(handles.ListboxTargetMarkers, 'Enable', 'off');
  1289. set(handles.ButtonAddMarker, 'Enable', 'off');
  1290. %** LOCK PRESTIM, POSTSTIM AND OVERLAP AS WELL? But accomodate lock settings.
  1291. % Note: if you do this, need to add UpdateTimeSettings to Select/ForceAdd/Remove data as well.
  1292. else
  1293. set(handles.ListboxTargetMarkers, 'Enable', 'on');
  1294. set(handles.ButtonAddMarker, 'Enable', 'on');
  1295. end
  1296. set(handles.ListboxDetectedEvents, 'Enable', 'on');
  1297. set(handles.ListboxIncludedEvents, 'Enable', 'on');
  1298. set(handles.ListboxExcludedEvents, 'Enable', 'on');
  1299. set(handles.ButtonDetectEvents, 'Enable', 'on');
  1300. set(handles.ButtonIncludeEvent, 'Enable', 'on');
  1301. set(handles.ButtonExcludeEvent, 'Enable', 'on');
  1302. set(handles.ButtonResetEvents, 'Enable', 'on');
  1303. end
  1304. % If FT .mat files selected, check if EventInfo exists.
  1305. % If EventInfo exists, then check if continuous for T=0 event compatibility.
  1306. if strcmp(handles.gui.DataFiletype, 'Fieldtrip')
  1307. if ~isempty(EventInfoExist) && max(cellfun(@(x) x==0, EventInfoExist)) == 1 % If no exist
  1308. if strcmp(get(handles.ListboxTargetMarkers, 'Enable'), 'on')
  1309. message = {'WARNING:'; ''; % Only warns if transitioning from enabled to disabled.
  1310. 'Some of the selected FT datasets do not contain the "AllEventInfo" field.';
  1311. 'As a result, events settings are unavailable and files will be read as is.'; '';
  1312. 'To specify events, unselect files missing the required field (see status).';
  1313. 'Note: The "AllEventInfo" field is created for raw files read by [MEG]PLS.'};
  1314. msgbox(message);
  1315. end
  1316. handles.epoch.TargetMarkers = [];
  1317. handles.epoch.IncludedEvents = [];
  1318. handles.epoch.ExcludedEvents = [];
  1319. set(handles.ListboxDetectedEvents, 'Enable', 'off');
  1320. set(handles.ListboxTargetMarkers, 'Enable', 'off');
  1321. set(handles.ListboxIncludedEvents, 'Enable', 'off');
  1322. set(handles.ListboxExcludedEvents, 'Enable', 'off');
  1323. set(handles.ButtonDetectEvents, 'Enable', 'off');
  1324. set(handles.ButtonAddMarker, 'Enable', 'off');
  1325. set(handles.ButtonIncludeEvent, 'Enable', 'off');
  1326. set(handles.ButtonExcludeEvent, 'Enable', 'off');
  1327. set(handles.ButtonResetEvents, 'Enable', 'off');
  1328. else % if event info exists
  1329. if ~isempty(DataContinuous) && max(cellfun(@(x) x==0, DataContinuous)) == 1 % if non-continuous
  1330. if strcmp(get(handles.ListboxTargetMarkers, 'Enable'), 'on')
  1331. message = {'WARNING:'; ''; % Only warns if transitioning from enabled to disabled.
  1332. 'Some of the selected datasets have already been epoched.'; '';
  1333. 'Target T=0 Events for epoching can only be set for continuous datasets.';
  1334. 'To specify T=0 events, unselect the epoched datasets (see status box).'};
  1335. msgbox(message);
  1336. end
  1337. handles.epoch.TargetMarkers = [];
  1338. set(handles.ListboxTargetMarkers, 'Enable', 'off');
  1339. set(handles.ButtonAddMarker, 'Enable', 'off');
  1340. else
  1341. set(handles.ListboxTargetMarkers, 'Enable', 'on');
  1342. set(handles.ButtonAddMarker, 'Enable', 'on');
  1343. end
  1344. set(handles.ListboxDetectedEvents, 'Enable', 'on');
  1345. set(handles.ListboxIncludedEvents, 'Enable', 'on');
  1346. set(handles.ListboxExcludedEvents, 'Enable', 'on');
  1347. set(handles.ButtonDetectEvents, 'Enable', 'on');
  1348. set(handles.ButtonIncludeEvent, 'Enable', 'on');
  1349. set(handles.ButtonExcludeEvent, 'Enable', 'on');
  1350. set(handles.ButtonResetEvents, 'Enable', 'on');
  1351. end
  1352. end
  1353. % Update detected events listbox:
  1354. if isempty(handles.gui.DetectedEvents)
  1355. set(handles.ListboxDetectedEvents, 'String', []);
  1356. else
  1357. set(handles.ListboxDetectedEvents, 'String', handles.gui.DetectedEvents(:,3));
  1358. end
  1359. CurrentIndex = max(get(handles.ListboxDetectedEvents, 'Value'));
  1360. MaxDetEvents = size(handles.gui.DetectedEvents, 1);
  1361. if isempty(CurrentIndex) || CurrentIndex == 0 || CurrentIndex > MaxDetEvents
  1362. set(handles.ListboxDetectedEvents, 'Value', MaxDetEvents);
  1363. end
  1364. % Update target markers listbox:
  1365. if isempty(handles.epoch.TargetMarkers)
  1366. set(handles.ListboxTargetMarkers, 'String', []);
  1367. else
  1368. set(handles.ListboxTargetMarkers, 'String', handles.epoch.TargetMarkers(:,3));
  1369. end
  1370. CurrentIndex = get(handles.ListboxTargetMarkers, 'Value');
  1371. MaxAddMarkers = size(handles.epoch.TargetMarkers, 1);
  1372. if isempty(CurrentIndex) || CurrentIndex == 0 || CurrentIndex > MaxAddMarkers
  1373. set(handles.ListboxTargetMarkers, 'Value', MaxAddMarkers);
  1374. end
  1375. % Update include events listbox:
  1376. if isempty(handles.epoch.IncludedEvents)
  1377. set(handles.ListboxIncludedEvents, 'String', []);
  1378. else
  1379. set(handles.ListboxIncludedEvents, 'String', handles.epoch.IncludedEvents(:,3));
  1380. end
  1381. CurrentIndex = get(handles.ListboxIncludedEvents, 'Value');
  1382. MaxIncEvents = size(handles.epoch.IncludedEvents, 1);
  1383. if isempty(CurrentIndex) || CurrentIndex == 0 || CurrentIndex > MaxIncEvents
  1384. set(handles.ListboxIncludedEvents, 'Value', MaxIncEvents);
  1385. end
  1386. % Update exclude events listbox:
  1387. if isempty(handles.epoch.ExcludedEvents)
  1388. set(handles.ListboxExcludedEvents, 'String', []);
  1389. else
  1390. set(handles.ListboxExcludedEvents, 'String', handles.epoch.ExcludedEvents(:,3));
  1391. end
  1392. CurrentIndex = get(handles.ListboxExcludedEvents, 'Value');
  1393. MaxExcEvents = size(handles.epoch.ExcludedEvents, 1);
  1394. if isempty(CurrentIndex) || CurrentIndex == 0 || CurrentIndex > MaxExcEvents
  1395. set(handles.ListboxExcludedEvents, 'Value', MaxExcEvents);
  1396. end
  1397. % Set output handles:
  1398. OutputHandles = handles;
  1399. %--- Load event settings & GUI panel: ---%
  1400. %----------------------------------------%
  1401. function OutputHandles = LoadEventSettings(InputHandles, LoadedMat)
  1402. handles = InputHandles;
  1403. % Load event settings:
  1404. handles.epoch.TargetMarkers = LoadedMat.epoch.TargetMarkers;
  1405. handles.epoch.IncludedEvents = LoadedMat.epoch.IncludedEvents;
  1406. handles.epoch.ExcludedEvents = LoadedMat.epoch.ExcludedEvents;
  1407. % Load GUI panel:
  1408. set(handles.ListboxTargetMarkers, 'String', handles.epoch.TargetMarkers);
  1409. set(handles.ListboxIncludedEvents, 'String', handles.epoch.IncludedEvents);
  1410. set(handles.ListboxExcludedEvents, 'String', handles.epoch.ExcludedEvents);
  1411. % Set output handles:
  1412. OutputHandles = handles;
  1413. %--- Reset event settings & GUI panel: ---%
  1414. %-----------------------------------------%
  1415. function OutputHandles = ResetEventSettings(InputHandles)
  1416. handles = InputHandles;
  1417. % Reset event settings:
  1418. handles.gui.DetectedEvents = [];
  1419. handles.epoch.TargetMarkers = [];
  1420. handles.epoch.IncludedEvents = [];
  1421. handles.epoch.ExcludedEvents = [];
  1422. % Reset GUI event panel:
  1423. set(handles.ListboxDetectedEvents, 'String', []);
  1424. set(handles.ListboxDetectedEvents, 'Value', 1);
  1425. set(handles.ListboxTargetMarkers, 'String', []);
  1426. set(handles.ListboxTargetMarkers, 'Value', 1);
  1427. set(handles.ListboxIncludedEvents, 'String', []);
  1428. set(handles.ListboxIncludedEvents, 'Value', 1);
  1429. set(handles.ListboxExcludedEvents, 'String', []);
  1430. set(handles.ListboxExcludedEvents, 'Value', 1);
  1431. % Set output handles:
  1432. OutputHandles = handles;
  1433. %====================================================%
  1434. % FUNCTIONS FOR VIEWING / SPECIFYING CONDITION ID'S: %
  1435. %====================================================%
  1436. %--- Executes on selection change in ListboxCondID. ---%
  1437. %------------------------------------------------------%
  1438. function ListboxCondID_Callback(hObject, eventdata, handles)
  1439. % hObject handle to ListboxTargetMarkers (see GCBO)
  1440. % eventdata reserved - to be defined in a future version of MATLAB
  1441. % handles structure with handles and user data (see GUIDATA)
  1442. %--- Executes on button press in ButtonAddCondID. ---%
  1443. %----------------------------------------------------%
  1444. function ButtonAddCondID_Callback(hObject, eventdata, handles)
  1445. if isempty(handles.name.DataID) || isempty(handles.paths.DataID)
  1446. msgbox('Warning: Create or load DataID first.', 'Warning:');
  1447. return;
  1448. end
  1449. if isempty(handles.name.CurrentGroupID)
  1450. msgbox('Warning: Create or load a GroupID first.', 'Warning:');
  1451. return;
  1452. end
  1453. % Enter name of CondID:
  1454. UserInput = inputdlg('Enter CondID name:', 'Create new CondID:');
  1455. UserInput = deblank(UserInput);
  1456. UserInput = regexprep(UserInput, '\s+', '_');
  1457. if isempty(char(UserInput))
  1458. return; % If user cancels
  1459. end
  1460. PathInputID = [handles.paths.CurrentGroupID,'/',UserInput{1}];
  1461. if exist(PathInputID, 'dir')
  1462. msgbox('Error: CondID already exists.', 'Error:')
  1463. return;
  1464. end
  1465. % Create CondID folder:
  1466. status = mkdir(PathInputID);
  1467. if status == 0
  1468. msgbox('Error: Failed to create CondID folder.', 'Error:')
  1469. return;
  1470. end
  1471. % Save handles:
  1472. handles = DetectCondIDs (handles);
  1473. handles = UpdateCondIDSettings (handles);
  1474. guidata(hObject, handles);
  1475. %--- Executes on button press in ButtonRmvCondID. ---%
  1476. %----------------------------------------------------%
  1477. function ButtonRmvCondID_Callback(hObject, eventdata, handles)
  1478. if isempty(handles.name.CondID)
  1479. return;
  1480. end
  1481. prompt = {'WARNING:'; '';
  1482. 'If you remove this CondID, all preprocessed data inside the';
  1483. 'CondID folder will also be lost.'; ''; 'Do you wish to continue?'};
  1484. DeleteCond = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'NO');
  1485. if strcmp(DeleteCond, 'NO')
  1486. return;
  1487. end
  1488. % Removes selected CondID and its respective folder:
  1489. SelectedIndex = get(handles.ListboxCondID, 'Value');
  1490. SelectedCondID = handles.name.CondID{SelectedIndex};
  1491. status = rmdir([handles.paths.CurrentGroupID,'/',SelectedCondID], 's');
  1492. if status == 0
  1493. msgbox('Error: Failed to remove CondID folder.', 'Error:')
  1494. return;
  1495. end
  1496. % If removed CondID is the CurrentCondID:
  1497. if strcmp(SelectedCondID, handles.name.CurrentCondID)
  1498. handles = ResetCondIDSettings(handles);
  1499. handles = ResetStatusSettings(handles);
  1500. end
  1501. % Save handles:
  1502. handles = DetectCondIDs (handles);
  1503. handles = UpdateCondIDSettings (handles);
  1504. guidata(hObject, handles);
  1505. %--- Executes on button press in ButtonSetCurrentCondID. ---%
  1506. %-----------------------------------------------------------%
  1507. function ButtonSetCurrentCondID_Callback(hObject, eventdata, handles)
  1508. if isempty(handles.name.CondID)
  1509. return;
  1510. end
  1511. % Set selected CondID in ListboxCondID as current condition:
  1512. SelectedIndex = get(handles.ListboxCondID, 'Value');
  1513. SelectedCondID = handles.name.CondID{SelectedIndex};
  1514. if ~isempty(handles.name.CurrentCondID) &&...
  1515. strcmp(SelectedCondID, handles.name.CurrentCondID)
  1516. return;
  1517. end
  1518. handles.name.CurrentCondID = SelectedCondID;
  1519. handles.paths.CurrentCondID = [handles.paths.CurrentGroupID,'/',SelectedCondID];
  1520. set(handles.TextboxCurrentCondID, 'String', handles.name.CurrentCondID);
  1521. message = {['TARGET CONDITION-ID HAS BEEN SET TO: ',handles.name.CurrentCondID]; '';
  1522. 'Trials defined by current events will be epoched as this CondID.';
  1523. 'Preprocessing settings will be applied to files for this CondID.'};
  1524. msgbox(message, 'Update:')
  1525. % Update input settings & GUI panels:
  1526. handles = DetectCondIDs (handles);
  1527. handles = UpdateCondIDSettings (handles);
  1528. set(handles.CheckboxShowOutputStatus, 'Value', 1);
  1529. handles = DetectStatus (handles);
  1530. handles = UpdateStatusSettings (handles);
  1531. % Save handles:
  1532. guidata(hObject, handles);
  1533. %--- Textbox to display current target CondID: ---%
  1534. %-------------------------------------------------%
  1535. function TextboxCurrentCondID_Callback(hObject, eventdata, handles)
  1536. EnteredText = get(handles.TextboxCurrentCondID, 'String');
  1537. if ~isequal(EnteredText, handles.name.CurrentCondID)
  1538. set(handles.TextboxCurrentCondID, 'String', handles.name.CurrentCondID);
  1539. msgbox('Note: Use button to change current target CondID.')
  1540. end
  1541. %--- Detect available CondID folders CurrentGroupID: ---%
  1542. %-------------------------------------------------------%
  1543. function OutputHandles = DetectCondIDs(InputHandles)
  1544. handles = InputHandles;
  1545. % Check if DataID has been selected & if MEGdata folder exists:
  1546. if isempty(handles.name.DataID) || isempty(handles.paths.DataID)
  1547. msgbox('Warning: Create or load DataID first.', 'Warning:');
  1548. return;
  1549. end
  1550. if isempty(handles.name.CurrentGroupID)
  1551. msgbox('Warning: Create or load a GroupID first.', 'Warning:');
  1552. return;
  1553. end
  1554. % Detect CondID folders for selected DataID & GroupID:
  1555. DetectedCondIDs = dir([handles.paths.CurrentGroupID,'/*']);
  1556. RemoveIndex = [];
  1557. for c = 1:length(DetectedCondIDs)
  1558. if DetectedCondIDs(c).isdir ~= 1 || ismember(DetectedCondIDs(c).name, {'.', '..'})
  1559. RemoveIndex = [RemoveIndex, c]; % Get unwanted indices
  1560. end
  1561. end
  1562. DetectedCondIDs(RemoveIndex) = [];
  1563. DetectedCondIDs = {DetectedCondIDs.name};
  1564. handles.name.CondID = DetectedCondIDs;
  1565. % Save as output:
  1566. OutputHandles = handles;
  1567. %--- Update CondID settings & GUI panel: ---%
  1568. %-------------------------------------------%
  1569. function OutputHandles = UpdateCondIDSettings(InputHandles)
  1570. handles = InputHandles;
  1571. % Update listbox:
  1572. set(handles.ListboxCondID, 'String', handles.name.CondID);
  1573. CurrentIndex = get(handles.ListboxCondID, 'Value');
  1574. MaxCondIndex = length(handles.name.CondID);
  1575. if isempty(CurrentIndex) || CurrentIndex == 0 || CurrentIndex > MaxCondIndex
  1576. set(handles.ListboxCondID, 'Value', MaxCondIndex);
  1577. end
  1578. set(handles.TextboxCurrentCondID, 'String', handles.name.CurrentCondID);
  1579. % Set output handles:
  1580. OutputHandles = handles;
  1581. %--- Load CondID settings & GUI panel: ---%
  1582. %-----------------------------------------%
  1583. function OutputHandles = LoadCondIDSettings(InputHandles, LoadedMat)
  1584. handles = InputHandles;
  1585. % Load CondID settings:
  1586. % Note: For handles.name.CondID, just redetect conds.
  1587. handles.name.CurrentCondID = LoadedMat.name.CurrentCondID;
  1588. handles.paths.CurrentCondID = [handles.paths.CurrentGroupID,'/',handles.name.CurrentCondID];
  1589. % Load GUI panel:
  1590. set(handles.TextboxCurrentCondID, 'String', handles.name.CurrentCondID);
  1591. % Set output handles:
  1592. OutputHandles = handles;
  1593. %--- Reset CondID settings & GUI panel: ---%
  1594. %------------------------------------------%
  1595. function OutputHandles = ResetCondIDSettings(InputHandles)
  1596. handles = InputHandles;
  1597. % Reset CondID settings:
  1598. handles.name.CondID = [];
  1599. handles.name.CurrentCondID = [];
  1600. handles.paths.CurrentCondID = [];
  1601. % Reset GUI CondID panel:
  1602. set(handles.ListboxCondID, 'String', []);
  1603. set(handles.ListboxCondID, 'Value', 1);
  1604. set(handles.TextboxCurrentCondID, 'String', []);
  1605. % Set output handles:
  1606. OutputHandles = handles;
  1607. %===============================%
  1608. % FUNCTIONS FOR STATUS UPDATES: %
  1609. %===============================%
  1610. %--- Executes on selection change in ListboxStatus. ---%
  1611. %------------------------------------------------------%
  1612. function ListboxStatus_Callback(hObject, eventdata, handles)
  1613. SelectedIndex = get(handles.ListboxStatus, 'Value');
  1614. set(handles.ListboxSubjID, 'Value', SelectedIndex);
  1615. set(handles.ListboxInputData, 'Value', SelectedIndex);
  1616. %--- Executes on button press in CheckboxShowOutputStatus. ---%
  1617. %-------------------------------------------------------------%
  1618. function CheckboxShowOutputStatus_Callback(hObject, eventdata, handles)
  1619. handles = DetectStatus (handles);
  1620. handles = UpdateStatusSettings (handles);
  1621. guidata(hObject, handles);
  1622. %--- Executes on button press in ButtonUpdateStatus. ---%
  1623. %-------------------------------------------------------%
  1624. function ButtonUpdateStatus_Callback(hObject, eventdata, handles)
  1625. handles = DetectStatus (handles);
  1626. handles = UpdateStatusSettings (handles);
  1627. guidata(hObject, handles);
  1628. %--- Function to acquire status of data: ---%
  1629. %-------------------------------------------%
  1630. function OutputHandles = DetectStatus(InputHandles)
  1631. handles = InputHandles;
  1632. StatusWaitbar = waitbar(0,...
  1633. 'Please wait. Scanning Subject Datasets:', 'Windowstyle', 'modal');
  1634. for s = 1:length(handles.name.SubjID)
  1635. waitbar(s/length(handles.name.SubjID), StatusWaitbar);
  1636. StatusMsg = []; % Status will be built upon
  1637. if ~isempty(handles.name.CurrentCondID)
  1638. EpochedFile = [handles.paths.CurrentCondID,'/',handles.name.SubjID{s},'_PreprocMEG.mat'];
  1639. else
  1640. EpochedFile = [];
  1641. end
  1642. if ~exist(EpochedFile, 'file') || get(handles.CheckboxShowOutputStatus, 'Value') == 0
  1643. if isempty(handles.paths.DataFullpath{s}) % If data not selected.
  1644. handles.gui.Status{s} = 'Warning: Select dataset for this subject.';
  1645. continue;
  1646. end
  1647. if exist(handles.paths.DataFullpath{s}, 'file') % If input data found
  1648. StatusMsg = 'Input dataset found';
  1649. else
  1650. handles.gui.Status{s} = 'Error: Dataset could not be found. Reselect file.';
  1651. continue;
  1652. end
  1653. if handles.gui.ReadHdrSuccess{s} == 0
  1654. StatusMsg = [StatusMsg,'. Failed to read Hdr.'];
  1655. elseif handles.gui.ReadHdrSuccess{s} == 1
  1656. switch handles.gui.DataContinuous{s}
  1657. case 1
  1658. StatusMsg = [StatusMsg,' (Continuous)'];
  1659. case 0
  1660. NumTrials = [num2str(handles.gui.InputNumTrials{s}),' trials'];
  1661. StatusMsg = [StatusMsg,' (Epoched: ',NumTrials,')'];
  1662. end
  1663. switch handles.gui.EventInfoExist{s}
  1664. case 1
  1665. StatusMsg = [StatusMsg,'. Event info found.'];
  1666. case 0
  1667. StatusMsg = [StatusMsg,'. Event info missing.'];
  1668. end
  1669. end
  1670. elseif get(handles.CheckboxShowOutputStatus, 'Value') == 1
  1671. EpochedData = LoadFTmat(EpochedFile, 'PreprocMEG');
  1672. if isempty(EpochedData)
  1673. StatusMsg = 'Error: Output file found, but contains errors. See ErrorLog.';
  1674. else
  1675. NumTrials = size(EpochedData.trial, 2);
  1676. StatusMsg = ['Output file detected: ',num2str(NumTrials),' trials.'];
  1677. end
  1678. end
  1679. handles.gui.Status{s} = StatusMsg;
  1680. end % Subj
  1681. delete(StatusWaitbar);
  1682. % Save as output:
  1683. OutputHandles = handles;
  1684. % Remove ErrorLog if empty:
  1685. if exist([pwd,'/ErrorLog_PreprocMEG.txt'], 'file')
  1686. LogCheck = dir('ErrorLog_PreprocMEG.txt');
  1687. if LogCheck.bytes == 0
  1688. delete('ErrorLog_PreprocMEG.txt');
  1689. end
  1690. end
  1691. %--- Update status settings & GUI panel: ---%
  1692. %-------------------------------------------%
  1693. function OutputHandles = UpdateStatusSettings(InputHandles)
  1694. handles = InputHandles;
  1695. % Make sure cells initialized:
  1696. for s = 1:length(handles.name.SubjID)
  1697. try
  1698. handles.gui.Status{s};
  1699. catch
  1700. handles.gui.Status{s} = [];
  1701. end
  1702. end
  1703. % Update listbox:
  1704. set(handles.ListboxStatus, 'String', handles.gui.Status);
  1705. % Set output handles:
  1706. OutputHandles = handles;
  1707. %--- Reset status settings & GUI panel: ---%
  1708. %------------------------------------------%
  1709. function OutputHandles = ResetStatusSettings(InputHandles)
  1710. handles = InputHandles;
  1711. % Reset status settings:
  1712. handles.gui.Status = [];
  1713. for s = 1:length(handles.name.SubjID)
  1714. handles.gui.Status{s} = [];
  1715. end
  1716. % Reset GUI status panel:
  1717. set(handles.ListboxStatus, 'String', []);
  1718. set(handles.ListboxStatus, 'Value', 1);
  1719. % Set output handles:
  1720. OutputHandles = handles;
  1721. %===============================================%
  1722. % FUNCTIONS FOR SAVING & LOADING PREPROC INPUT: %
  1723. %===============================================%
  1724. %--- Executes on button press in ButtonSaveInput. ---%
  1725. %----------------------------------------------------%
  1726. function ButtonSaveInput_Callback(hObject, eventdata, handles)
  1727. if isempty(handles.paths.Rootpath)
  1728. msgbox('Warning: Select root directory first.', 'Warning:');
  1729. return;
  1730. end
  1731. if isempty(handles.name.DataID) || isempty(handles.paths.DataID)
  1732. msgbox('Warning: Create or load DataID first.', 'Warning:');
  1733. return;
  1734. end
  1735. if isempty(handles.name.CurrentGroupID)
  1736. msgbox('Warning: Group has not been selected yet.', 'Warning:');
  1737. return;
  1738. end
  1739. if isempty(handles.name.CurrentCondID)
  1740. msgbox('Warning: Current CondID has not been selected yet.', 'Warning:');
  1741. return;
  1742. end
  1743. if isempty(handles.name.SubjID) || isempty(handles.paths.DataFullpath)
  1744. msgbox('Warning: Subjects & Datasets have not been selected.', 'Warning:');
  1745. return;
  1746. end
  1747. % Make sure rootpath & DataID don't have spaces (will cause issues for AFNI later):
  1748. CheckSpaces1 = strfind(handles.paths.Rootpath, ' ');
  1749. CheckSpaces2 = strfind(handles.paths.DataID, ' ');
  1750. if ~isempty(CheckSpaces1) || ~isempty(CheckSpaces2)
  1751. message = {'Error: Target directory or DataID contains spaces.';
  1752. 'AFNI functions cannot read folder & file paths with spaces.';
  1753. 'AFNI functions are required for file conversions later on.'};
  1754. msgbox(message, 'Error:')
  1755. return;
  1756. end
  1757. % Check save path:
  1758. SavePath = [handles.paths.CurrentGroupID,...
  1759. '/PreprocInputMEG_',handles.name.CurrentCondID,'.mat'];
  1760. if exist(SavePath, 'file')
  1761. prompt = {'WARNING:'; '';
  1762. 'PreprocInputMEG .mat file already exists for this CondID.';
  1763. 'Are you sure you wish to OVERWRITE the existing file?'};
  1764. OverwriteMat = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'NO');
  1765. if strcmp(OverwriteMat, 'NO')
  1766. return;
  1767. else
  1768. delete(SavePath);
  1769. end
  1770. end
  1771. % Save input parameters for current GroupID and CondID:
  1772. name.DataID = handles.name.DataID;
  1773. name.SubjID = handles.name.SubjID;
  1774. name.CurrentGroupID = handles.name.CurrentGroupID;
  1775. name.CurrentCondID = handles.name.CurrentCondID;
  1776. paths = handles.paths; % Rmv GUI only paths that aren't in load fcns.
  1777. paths = rmfield(paths, 'Rootpath'); % - These paths auto-adapt if folders moved.
  1778. paths = rmfield(paths, 'DataID');
  1779. paths = rmfield(paths, 'CurrentGroupID');
  1780. paths = rmfield(paths, 'CurrentCondID');
  1781. epoch.TargetMarkers = handles.epoch.TargetMarkers;
  1782. epoch.IncludedEvents = handles.epoch.IncludedEvents;
  1783. epoch.ExcludedEvents = handles.epoch.ExcludedEvents;
  1784. gui = handles.gui; % Rmv GUI only parameters that aren't loaded.
  1785. gui = rmfield(gui, 'Status'); % - These auto-adapt once loaded.
  1786. gui = rmfield(gui, 'DetectedEvents');
  1787. gui = rmfield(gui, 'LockPreprocSettings');
  1788. CheckSavePath(SavePath, 'PreprocMEG');
  1789. save(SavePath, 'name', 'paths', 'epoch', 'gui');
  1790. % Feedback:
  1791. if exist(SavePath, 'file')
  1792. msgbox('Current input parameters successfully saved.', 'Success')
  1793. else
  1794. msgbox('Error: Failed to save input parameters.', 'Error:')
  1795. end
  1796. %--- Executes on button press in ButtonLoadInput. ---%
  1797. %----------------------------------------------------%
  1798. function ButtonLoadInput_Callback(hObject, eventdata, handles)
  1799. if isempty(handles.paths.Rootpath)
  1800. msgbox('Warning: Select root directory first.', 'Warning:');
  1801. return;
  1802. end
  1803. if isempty(handles.name.DataID) || isempty(handles.paths.DataID)
  1804. msgbox('Warning: Create or load DataID first.', 'Warning:');
  1805. return;
  1806. end
  1807. if isempty(handles.name.CurrentGroupID)
  1808. msgbox('Warning: Create or load GroupID.', 'Warning:');
  1809. return;
  1810. end
  1811. % Select and load PreprocInputMEG .mat:
  1812. [matfile, matpath] = uigetfile([handles.paths.CurrentGroupID,...
  1813. '/PreprocInputMEG_*.mat'], 'Select PreprocInputMEG .mat:', 'MultiSelect', 'off');
  1814. if matfile == 0
  1815. msgbox('Note: Load cancelled. File was not selected.', 'Note:');
  1816. return;
  1817. end
  1818. % Start Waitbox:
  1819. WaitBox = StartWaitBox('LOADING INPUT SETTINGS:');
  1820. % Reset input settings & GUI panels:
  1821. handles = ResetSubjIDSettings (handles);
  1822. handles = ResetInputDataSettings (handles);
  1823. handles = ResetEventSettings (handles);
  1824. handles = ResetCondIDSettings (handles);
  1825. handles = ResetStatusSettings (handles);
  1826. % Load input settings & GUI panels:
  1827. LoadedMat = load([matpath,matfile]);
  1828. handles = LoadSubjIDSettings (handles, LoadedMat);
  1829. handles = LoadInputDataSettings (handles, LoadedMat);
  1830. handles = LoadEventSettings (handles, LoadedMat);
  1831. handles = LoadCondIDSettings (handles, LoadedMat);
  1832. % Redetect CondID folders & dataset events:
  1833. handles = DetectCondIDs (handles);
  1834. handles = DetectDatasetEvents (handles);
  1835. % Update input settings & GUI panels:
  1836. handles = UpdateSubjIDSettings (handles);
  1837. handles = UpdateInputDataSettings (handles);
  1838. handles = UpdateEventSettings (handles);
  1839. handles = UpdateCondIDSettings (handles);
  1840. handles = UpdateStatusSettings (handles);
  1841. % Save handles:
  1842. guidata(hObject, handles);
  1843. close(WaitBox);
  1844. %==============================%
  1845. % FUNCTIONS FOR TIME SETTINGS: %
  1846. %==============================%
  1847. %--- User enters prestimulus time here: ---%
  1848. %------------------------------------------%
  1849. function TextboxPrestimTime_Callback(hObject, eventdata, handles)
  1850. PrestimTime = str2num(get(handles.TextboxPrestimTime, 'String'));
  1851. PoststimTime = str2num(get(handles.TextboxPoststimTime, 'String'));
  1852. if isempty(PrestimTime)
  1853. msgbox('Error: Pre-stimulus time must be specified.', 'Error:');
  1854. return;
  1855. end
  1856. if ~isempty(PoststimTime) && (PrestimTime < 0 && (PrestimTime*-1 > PoststimTime))
  1857. msgbox('Error: Epoch start time cannot exceed end time.', 'Error:');
  1858. set(handles.TextboxPrestimTime, 'String', []);
  1859. return;
  1860. end
  1861. if PrestimTime < 0
  1862. prompt = {'Warning:'; '';
  1863. ['You have input a negative amount of prestimulus time: ',num2str(PrestimTime)];
  1864. ['This means your epoch will currently start at: ',num2str(abs(PrestimTime)),'s']};
  1865. msgbox(prompt, 'Warning:')
  1866. end
  1867. % Adjust inc. & exc. event search times and baseline:
  1868. EpochStartTime = PrestimTime * -1;
  1869. EpochEndTime = PoststimTime;
  1870. set(handles.TextboxIncEventStartTime, 'String', num2str(EpochStartTime, '%1.3f'));
  1871. set(handles.TextboxExcEventStartTime, 'String', num2str(EpochStartTime, '%1.3f'));
  1872. set(handles.TextboxBaselineStart, 'String', num2str(EpochStartTime, '%1.3f'));
  1873. % Adjust default overlap threshold:
  1874. if EpochStartTime > 0
  1875. set(handles.TextboxOverlapThreshold, 'String', num2str(0, '%1.3f'));
  1876. else
  1877. set(handles.TextboxOverlapThreshold, 'String', num2str(abs(EpochStartTime), '%1.3f'));
  1878. end
  1879. % Adjust padding length:
  1880. EpochLength = EpochEndTime - EpochStartTime;
  1881. if EpochLength < 5 % If less than 5s, pad to 10s (for sharp DFT filter).
  1882. set(handles.TextboxPaddingLength, 'String', num2str(10, '%1.3f'));
  1883. else
  1884. PadToLength = EpochLength + 5; % Otherwise, use 5s of padding.
  1885. set(handles.TextboxPaddingLength, 'String', num2str(PadToLength, '%1.3f'));
  1886. end
  1887. % Save handles:
  1888. handles = UpdateEpochSettings (handles);
  1889. handles = UpdateBaselineSettings (handles);
  1890. guidata(hObject, handles);
  1891. %--- User enters poststimulus time here: ---%
  1892. %-------------------------------------------%
  1893. function TextboxPoststimTime_Callback(hObject, eventdata, handles)
  1894. PoststimTime = str2num(get(handles.TextboxPoststimTime, 'String'));
  1895. PrestimTime = str2num(get(handles.TextboxPrestimTime, 'String'));
  1896. if isempty(PoststimTime)
  1897. msgbox('Error: Post-stimulus time must be specified.', 'Error:');
  1898. return;
  1899. end
  1900. if ~isempty(PrestimTime) && (PrestimTime < 0 && (PrestimTime*-1 > PoststimTime))
  1901. msgbox('Error: Epoch end time cannot be less than start time.', 'Error:');
  1902. set(handles.TextboxPoststimTime, 'String', []);
  1903. return;
  1904. end
  1905. % Adjust inc. & exc. event search times:
  1906. EpochStartTime = PrestimTime * -1;
  1907. EpochEndTime = PoststimTime;
  1908. set(handles.TextboxIncEventEndTime, 'String', num2str(EpochEndTime, '%1.3f'));
  1909. set(handles.TextboxExcEventEndTime, 'String', num2str(EpochEndTime, '%1.3f'));
  1910. % Adjust padding length:
  1911. EpochLength = EpochEndTime - EpochStartTime;
  1912. if EpochLength < 5 % If less than 5s, pad to 10s (for sharp DFT filter).
  1913. set(handles.TextboxPaddingLength, 'String', num2str(10, '%1.3f'));
  1914. else
  1915. PadToLength = EpochLength + 5; % Otherwise, use 5s of padding.
  1916. set(handles.TextboxPaddingLength, 'String', num2str(PadToLength, '%1.3f'));
  1917. end
  1918. % Save handles:
  1919. handles = UpdateEpochSettings(handles);
  1920. guidata(hObject, handles);
  1921. %--- User enters overlap threshold length here: ---%
  1922. %--------------------------------------------------%
  1923. function TextboxOverlapThreshold_Callback(hObject, eventdata, handles)
  1924. OverlapThreshold = str2num(get(handles.TextboxOverlapThreshold, 'String'));
  1925. if isempty(OverlapThreshold)
  1926. msgbox('Error: Overlap threshold must be specified.', 'Error:')
  1927. set(handles.TextboxOverlapThreshold, 'String', num2str(0, '%1.3f'));
  1928. return;
  1929. end
  1930. handles = UpdateEpochSettings(handles);
  1931. guidata(hObject, handles);
  1932. %--- User enters start search time for include events: ---%
  1933. %---------------------------------------------------------%
  1934. function TextboxIncEventStartTime_Callback(hObject, eventdata, handles)
  1935. if isempty(handles.time.Start) || isempty(handles.time.End)
  1936. msgbox('Warning: Specify prestim & poststim time first.', 'Warning:')
  1937. return;
  1938. end
  1939. StartTime = str2num(get(handles.TextboxIncEventStartTime, 'String'));
  1940. EndTime = str2num(get(handles.TextboxIncEventEndTime, 'String'));
  1941. if isempty(StartTime) && ~isempty(handles.epoch.IncludedEvents)
  1942. msgbox('Error: Need to specify start search time for included events.', 'Error:')
  1943. set(handles.TextboxIncEventStartTime, 'String', num2str(handles.time.Start, '%1.3f'));
  1944. return;
  1945. end
  1946. if (StartTime < handles.time.Start) || (StartTime > handles.time.End)
  1947. msgbox('Error: Specified time is outside bounds of epoch time.', 'Error:')
  1948. set(handles.TextboxIncEventStartTime, 'String', num2str(handles.time.Start, '%1.3f'));
  1949. return;
  1950. end
  1951. if StartTime > EndTime
  1952. msgbox('Error: Start time cannot be greater than end time.', 'Error:')
  1953. set(handles.TextboxIncEventStartTime, 'String', num2str(handles.time.Start, '%1.3f'));
  1954. return;
  1955. end
  1956. handles = UpdateEpochSettings(handles);
  1957. guidata(hObject, handles);
  1958. %--- User enters end search time for include events: ---%
  1959. %-------------------------------------------------------%
  1960. function TextboxIncEventEndTime_Callback(hObject, eventdata, handles)
  1961. if isempty(handles.time.Start) || isempty(handles.time.End)
  1962. msgbox('Warning: Specify prestim & poststim time first.', 'Warning:')
  1963. return;
  1964. end
  1965. EndTime = str2num(get(handles.TextboxIncEventEndTime, 'String'));
  1966. StartTime = str2num(get(handles.TextboxIncEventStartTime, 'String'));
  1967. if isempty(EndTime) && ~isempty(handles.epoch.IncludedEvents)
  1968. msgbox('Error: Need to specify end search time for included events.', 'Error:')
  1969. set(handles.TextboxIncEventEndTime, 'String', num2str(handles.time.End, '%1.3f'));
  1970. return;
  1971. end
  1972. if (EndTime > handles.time.End) || (EndTime < handles.time.Start)
  1973. msgbox('Error: Specified time is outside bounds of epoch time.', 'Error:')
  1974. set(handles.TextboxIncEventEndTime, 'String', num2str(handles.time.End, '%1.3f'));
  1975. return;
  1976. end
  1977. if EndTime < StartTime
  1978. msgbox('Error: End time cannot be greater than start time.', 'Error:')
  1979. set(handles.TextboxIncEventEndTime, 'String', num2str(handles.time.End, '%1.3f'));
  1980. return;
  1981. end
  1982. handles = UpdateEpochSettings(handles);
  1983. guidata(hObject, handles);
  1984. %--- User enters start search time for exclude events: ---%
  1985. %---------------------------------------------------------%
  1986. function TextboxExcEventStartTime_Callback(hObject, eventdata, handles)
  1987. if isempty(handles.time.Start) || isempty(handles.time.End)
  1988. msgbox('Warning: Specify prestim & poststim time first.', 'Warning:')
  1989. return;
  1990. end
  1991. StartTime = str2num(get(handles.TextboxExcEventStartTime, 'String'));
  1992. EndTime = str2num(get(handles.TextboxExcEventEndTime, 'String'));
  1993. if isempty(StartTime) && ~isempty(handles.epoch.ExcludedEvents)
  1994. msgbox('Error: Need to specify start search time for excluded events.', 'Error:')
  1995. set(handles.TextboxExcEventStartTime, 'String', num2str(handles.time.Start, '%1.3f'));
  1996. return;
  1997. end
  1998. if (StartTime < handles.time.Start) || (StartTime > handles.time.End)
  1999. msgbox('Error: Specified time is outside bounds of epoch time.', 'Error:')
  2000. set(handles.TextboxExcEventStartTime, 'String', num2str(handles.time.Start, '%1.3f'));
  2001. return;
  2002. end
  2003. if StartTime > EndTime
  2004. msgbox('Error: Start time cannot be greater than end time.', 'Error:')
  2005. set(handles.TextboxExcEventStartTime, 'String', num2str(handles.time.Start, '%1.3f'));
  2006. return;
  2007. end
  2008. handles = UpdateEpochSettings(handles);
  2009. guidata(hObject, handles);
  2010. %--- User enters end search time for exclude events: ---%
  2011. %-------------------------------------------------------%
  2012. function TextboxExcEventEndTime_Callback(hObject, eventdata, handles)
  2013. if isempty(handles.time.Start) || isempty(handles.time.End)
  2014. msgbox('Warning: Specify prestim & poststim time first.', 'Warning:')
  2015. return;
  2016. end
  2017. EndTime = str2num(get(handles.TextboxExcEventEndTime, 'String'));
  2018. StartTime = str2num(get(handles.TextboxExcEventStartTime, 'String'));
  2019. if isempty(EndTime) && ~isempty(handles.epoch.ExcludedEvents)
  2020. msgbox('Error: Need to specify end search time for excluded events.', 'Error:')
  2021. set(handles.TextboxExcEventEndTime, 'String', num2str(handles.time.End, '%1.3f'));
  2022. return;
  2023. end
  2024. if (EndTime > handles.time.End) || (EndTime < handles.time.Start)
  2025. msgbox('Error: Specified time is outside bounds of epoch time.', 'Error:')
  2026. set(handles.TextboxExcEventEndTime, 'String', num2str(handles.time.End, '%1.3f'));
  2027. return;
  2028. end
  2029. if EndTime < StartTime
  2030. msgbox('Error: End time cannot be greater than start time.', 'Error:')
  2031. set(handles.TextboxExcEventEndTime, 'String', num2str(handles.time.End, '%1.3f'));
  2032. return;
  2033. end
  2034. handles = UpdateEpochSettings(handles);
  2035. guidata(hObject, handles);
  2036. %--- User enters filter padding length here: ---%
  2037. %-----------------------------------------------%
  2038. function TextboxPaddingLength_Callback(hObject, eventdata, handles)
  2039. FilterPadding = str2num(get(handles.TextboxPaddingLength, 'String'));
  2040. if isempty(FilterPadding)
  2041. set(handles.TextboxPaddingLength, 'String', num2str(0));
  2042. end
  2043. message = {'WARNING:'; '';
  2044. 'Data will be padded TO this specified length (not WITH this length)!';
  2045. 'This is due to the way FieldTrip reads and applies filter padding.'; '';
  2046. 'Ex: If your epoch length is 2s, and 10s of padding is specified,';
  2047. ' then 8s of padding will be added (data will be padded TO 10s).'; '';
  2048. 'As a result, if your epoch length is larger than the time specified';
  2049. 'here for filter padding, then no padding will be added.'};
  2050. msgbox(message, 'WARNING:'); %** ADD AUTOADJUST AS WELL
  2051. handles = UpdateEpochSettings(handles);
  2052. guidata(hObject, handles);
  2053. %--- Updates epoch & pad-length settings: ---%
  2054. %--------------------------------------------%
  2055. function OutputHandles = UpdateEpochSettings(InputHandles)
  2056. handles = InputHandles;
  2057. time = handles.time;
  2058. FTcfg = handles.FTcfg;
  2059. % Read GUI to update FTcfg:
  2060. FTcfg.DefineTrial.trialfun = 'ft_trialfun_general';
  2061. FTcfg.DefineTrial.trialdef.prestim = str2num(get(handles.TextboxPrestimTime, 'String'));
  2062. FTcfg.DefineTrial.trialdef.poststim = str2num(get(handles.TextboxPoststimTime, 'String'));
  2063. FTcfg.Preproc.padding = str2num(get(handles.TextboxPaddingLength, 'String'));
  2064. time.Start = str2num(get(handles.TextboxPrestimTime, 'String')) * -1;
  2065. time.End = str2num(get(handles.TextboxPoststimTime, 'String'));
  2066. time.OverlapThresh = str2num(get(handles.TextboxOverlapThreshold, 'String'));
  2067. time.IncEventStart = str2num(get(handles.TextboxIncEventStartTime, 'String'));
  2068. time.IncEventEnd = str2num(get(handles.TextboxIncEventEndTime, 'String'));
  2069. time.ExcEventStart = str2num(get(handles.TextboxExcEventStartTime, 'String'));
  2070. time.ExcEventEnd = str2num(get(handles.TextboxExcEventEndTime, 'String'));
  2071. % Enable/Disable GUI components:
  2072. set(findall(handles.PanelEpochTime, '-property', 'Enable'), 'Enable', 'on');
  2073. set(findall(handles.PanelFilterPadding, '-property', 'Enable'), 'Enable', 'on');
  2074. set(handles.TextboxPaddingLength, 'Enable', 'on');
  2075. set(handles.TextPaddingLength, 'Enable', 'on');
  2076. set(handles.TextboxIncEventStartTime, 'Enable', 'on');
  2077. set(handles.TextboxIncEventEndTime, 'Enable', 'on');
  2078. set(handles.TextIncEventStartTime, 'Enable', 'on');
  2079. set(handles.TextIncEventEndTime, 'Enable', 'on');
  2080. set(handles.TextboxExcEventStartTime, 'Enable', 'on');
  2081. set(handles.TextboxExcEventEndTime, 'Enable', 'on');
  2082. set(handles.TextExcEventStartTime, 'Enable', 'on');
  2083. set(handles.TextExcEventEndTime, 'Enable', 'on');
  2084. % Lock GUI panel if needed:
  2085. if strcmp(handles.gui.LockPreprocSettings, 'on')
  2086. set(findall(handles.PanelEpochTime, '-property', 'Enable'), 'Enable', 'off');
  2087. set(handles.TextboxOverlapThreshold, 'Enable', 'on'); % Keep thresh & inc/exc time on.
  2088. set(handles.TextOverlapThreshold, 'Enable', 'on');
  2089. set(findall(handles.PanelFilterPadding, '-property', 'Enable'), 'Enable', 'off');
  2090. set(handles.TextboxPaddingLength, 'Enable', 'off');
  2091. set(handles.TextPaddingLength, 'Enable', 'off');
  2092. end
  2093. % Set output handles:
  2094. handles.time = time;
  2095. handles.FTcfg = FTcfg;
  2096. OutputHandles = handles;
  2097. %--- Load epoch & pad length settings: ---%
  2098. %-----------------------------------------%
  2099. function OutputHandles = LoadEpochSettings(InputHandles, LoadedMat)
  2100. handles = InputHandles;
  2101. time = handles.time;
  2102. FTcfg = handles.FTcfg;
  2103. % Load FTcfg settings:
  2104. FTcfg.DefineTrial.trialfun = LoadedMat.FTcfg.DefineTrial.trialfun;
  2105. FTcfg.DefineTrial.trialdef.prestim = LoadedMat.FTcfg.DefineTrial.trialdef.prestim;
  2106. FTcfg.DefineTrial.trialdef.poststim = LoadedMat.FTcfg.DefineTrial.trialdef.poststim;
  2107. FTcfg.Preproc.padding = LoadedMat.FTcfg.Preproc.padding;
  2108. time.Start = LoadedMat.time.Start;
  2109. time.End = LoadedMat.time.End;
  2110. time.OverlapThresh = LoadedMat.time.OverlapThresh;
  2111. time.IncEventStart = LoadedMat.time.IncEventStart;
  2112. time.IncEventEnd = LoadedMat.time.IncEventEnd;
  2113. time.ExcEventStart = LoadedMat.time.ExcEventStart;
  2114. time.ExcEventEnd = LoadedMat.time.ExcEventEnd;
  2115. % Load GUI panel:
  2116. set(handles.TextboxPrestimTime, 'String', num2str(FTcfg.DefineTrial.trialdef.prestim));
  2117. set(handles.TextboxPoststimTime, 'String', num2str(FTcfg.DefineTrial.trialdef.poststim));
  2118. set(handles.TextboxPaddingLength, 'String', num2str(FTcfg.Preproc.padding));
  2119. set(handles.TextboxOverlapThreshold, 'String', num2str(time.OverlapThresh, '%1.3f'));
  2120. set(handles.TextboxIncEventStartTime, 'String', num2str(time.IncEventStart, '%1.3f'));
  2121. set(handles.TextboxIncEventEndTime, 'String', num2str(time.IncEventEnd, '%1.3f'));
  2122. set(handles.TextboxExcEventStartTime, 'String', num2str(time.ExcEventStart, '%1.3f'));
  2123. set(handles.TextboxExcEventEndTime, 'String', num2str(time.ExcEventEnd, '%1.3f'));
  2124. % Set output handles:
  2125. handles.FTcfg = FTcfg;
  2126. OutputHandles = handles;
  2127. %--- Reset epoch & pad length settings: ---%
  2128. %------------------------------------------%
  2129. function OutputHandles = ResetEpochSettings(InputHandles)
  2130. handles = InputHandles;
  2131. FTcfg = handles.FTcfg;
  2132. % Reset FTcfg default settings:
  2133. FTcfg.DefineTrial.trialfun = 'ft_trialfun_general';
  2134. FTcfg.DefineTrial.trialdef.prestim = 0.500;
  2135. FTcfg.DefineTrial.trialdef.poststim = 1.000;
  2136. FTcfg.Preproc.padding = 2;
  2137. time.Start = -0.500;
  2138. time.End = 1.000;
  2139. time.OverlapThresh = 0.500;
  2140. time.IncEventStart = time.Start;
  2141. time.IncEventEnd = time.End;
  2142. time.ExcEventStart = time.Start;
  2143. time.ExcEventEnd = time.End;
  2144. % Reset GUI panel:
  2145. set(handles.TextboxPrestimTime, 'String', num2str(0.500, '%1.3f'));
  2146. set(handles.TextboxPoststimTime, 'String', num2str(1.000, '%1.3f'));
  2147. set(handles.TextboxPaddingLength, 'String', num2str(2.000, '%1.3f'));
  2148. set(handles.TextboxOverlapThreshold, 'String', num2str(time.OverlapThresh, '%1.3f'));
  2149. set(handles.TextboxIncEventStartTime, 'String', num2str(time.IncEventStart, '%1.3f'));
  2150. set(handles.TextboxIncEventEndTime, 'String', num2str(time.IncEventEnd, '%1.3f'));
  2151. set(handles.TextboxExcEventStartTime, 'String', num2str(time.ExcEventStart, '%1.3f'));
  2152. set(handles.TextboxExcEventEndTime, 'String', num2str(time.ExcEventEnd, '%1.3f'));
  2153. % Set output handles:
  2154. handles.time = time;
  2155. handles.FTcfg = FTcfg;
  2156. OutputHandles = handles;
  2157. %=============================================%
  2158. % FUNCTIONS FOR BASELINE CORRECTION SETTINGS: %
  2159. %=============================================%
  2160. %--- GUI functions for baseline correction: ---%
  2161. %----------------------------------------------%
  2162. function CheckboxDemean_Callback(hObject, eventdata, handles)
  2163. handles = UpdateBaselineSettings(handles);
  2164. guidata(hObject, handles);
  2165. function CheckboxBaselineWholeTrial_Callback(hObject, eventdata, handles)
  2166. handles = UpdateBaselineSettings(handles);
  2167. guidata(hObject, handles);
  2168. %--- Textbox for user to enter baseline start time: ---%
  2169. %------------------------------------------------------%
  2170. function TextboxBaselineStart_Callback(hObject, eventdata, handles)
  2171. if get(handles.CheckboxDemean, 'Value') == 1
  2172. BaselineStart = str2num(get(handles.TextboxBaselineStart, 'String'));
  2173. BaselineEnd = str2num(get(handles.TextboxBaselineEnd, 'String'));
  2174. if isempty(BaselineStart)
  2175. msgbox('Error: Baseline start time not specified.', 'Error:');
  2176. set(handles.TextboxBaselineStart, 'String', num2str(handles.time.Start, '%1.3f'));
  2177. return;
  2178. end
  2179. if (BaselineStart < handles.time.Start) || (BaselineStart > handles.time.End)
  2180. msgbox('Error: Baseline time is outside bounds of epoch time.', 'Error:');
  2181. set(handles.TextboxBaselineStart, 'String', num2str(handles.time.Start, '%1.3f'));
  2182. return;
  2183. end
  2184. if BaselineStart > BaselineEnd
  2185. msgbox('Error: Baseline start cannot be greater than end time.', 'Error:');
  2186. set(handles.TextboxBaselineStart, 'String', num2str(handles.time.Start, '%1.3f'));
  2187. set(handles.TextboxBaselineEnd, 'String', num2str(0, '%1.3f'));
  2188. return;
  2189. end
  2190. end
  2191. handles = UpdateBaselineSettings(handles);
  2192. guidata(hObject, handles);
  2193. %--- Textbox for user to enter baseline end time: ---%
  2194. %----------------------------------------------------%
  2195. function TextboxBaselineEnd_Callback(hObject, eventdata, handles)
  2196. if get(handles.CheckboxDemean, 'Value') == 1
  2197. BaselineStart = str2num(get(handles.TextboxBaselineStart, 'String'));
  2198. BaselineEnd = str2num(get(handles.TextboxBaselineEnd, 'String'));
  2199. if isempty(BaselineEnd)
  2200. msgbox('Error: Baseline end time not specified.', 'Error:');
  2201. set(handles.TextboxBaselineEnd, 'String', num2str(0, '%1.3f'));
  2202. return;
  2203. end
  2204. if (BaselineEnd > handles.time.End) || (BaselineEnd < handles.time.Start)
  2205. msgbox('Error: Baseline time is outside bounds of epoch time.', 'Error:');
  2206. set(handles.TextboxBaselineEnd, 'String', num2str(0, '%1.3f'));
  2207. return;
  2208. end
  2209. if BaselineEnd < BaselineStart
  2210. msgbox('Error: Baseline end cannot be less than start time.', 'Error:');
  2211. set(handles.TextboxBaselineEnd, 'String', num2str(0, '%1.3f'));
  2212. set(handles.TextboxBaselineStart, 'String', num2str(handles.time.Start, '%1.3f'));
  2213. return;
  2214. end
  2215. end
  2216. handles = UpdateBaselineSettings(handles);
  2217. guidata(hObject, handles);
  2218. %--- Updates baseline settings & GUI panel: ---%
  2219. %----------------------------------------------%
  2220. function OutputHandles = UpdateBaselineSettings(InputHandles)
  2221. handles = InputHandles;
  2222. FTcfg = handles.FTcfg;
  2223. % Read GUI to update FTcfg:
  2224. if get(handles.CheckboxDemean, 'Value') == 1
  2225. FTcfg.Preproc.demean = 'yes';
  2226. if get(handles.CheckboxBaselineWholeTrial, 'Value') == 1
  2227. FTcfg.Preproc.baselinewindow = 'all';
  2228. else
  2229. BaselineStart = str2num(get(handles.TextboxBaselineStart, 'String'));
  2230. BaselineEnd = str2num(get(handles.TextboxBaselineEnd, 'String'));
  2231. FTcfg.Preproc.baselinewindow = [BaselineStart, BaselineEnd];
  2232. end
  2233. else
  2234. FTcfg.Preproc.demean = 'no';
  2235. FTcfg.Preproc.baselinewindow = [];
  2236. end
  2237. % Enable/Disable GUI baseline components:
  2238. if get(handles.CheckboxDemean, 'Value') == 1
  2239. set(findall(handles.PanelBaselineCorrection, '-property', 'Enable'), 'Enable', 'on');
  2240. if get(handles.CheckboxBaselineWholeTrial, 'Value') == 1
  2241. set(handles.TextboxBaselineStart, 'Enable', 'off');
  2242. set(handles.TextboxBaselineEnd, 'Enable', 'off');
  2243. set(handles.TextBaselineStart, 'Enable', 'off'); % Text header
  2244. set(handles.TextBaselineEnd, 'Enable', 'off'); % Text header
  2245. end
  2246. else
  2247. set(findall(handles.PanelBaselineCorrection, '-property', 'Enable'), 'Enable', 'off');
  2248. set(handles.CheckboxDemean, 'Enable', 'on');
  2249. end
  2250. % Lock GUI panel if needed:
  2251. if strcmp(handles.gui.LockPreprocSettings, 'on')
  2252. set(findall(handles.PanelBaselineCorrection, '-property', 'Enable'), 'Enable', 'off');
  2253. end
  2254. % Set output handles:
  2255. handles.FTcfg = FTcfg;
  2256. OutputHandles = handles;
  2257. %--- Load baseline settings & GUI panel: ---%
  2258. %-------------------------------------------%
  2259. function OutputHandles = LoadBaselineSettings(InputHandles, LoadedMat)
  2260. handles = InputHandles;
  2261. FTcfg = handles.FTcfg;
  2262. % Load FTcfg settings:
  2263. FTcfg.Preproc.demean = LoadedMat.FTcfg.Preproc.demean;
  2264. FTcfg.Preproc.baselinewindow = LoadedMat.FTcfg.Preproc.baselinewindow;
  2265. % Load GUI panel:
  2266. if strcmp(FTcfg.Preproc.demean, 'yes')
  2267. set(handles.CheckboxDemean, 'Value', 1);
  2268. if strcmp(FTcfg.Preproc.baselinewindow, 'all')
  2269. set(handles.CheckboxBaselineWholeTrial, 'Value', 1);
  2270. set(handles.TextboxBaselineStart, 'String', []);
  2271. set(handles.TextboxBaselineEnd, 'String', []);
  2272. else
  2273. BaselineStart = num2str(FTcfg.Preproc.baselinewindow(1));
  2274. BaselineEnd = num2str(FTcfg.Preproc.baselinewindow(2));
  2275. set(handles.CheckboxBaselineWholeTrial, 'Value', 0);
  2276. set(handles.TextboxBaselineStart, 'String', BaselineStart);
  2277. set(handles.TextboxBaselineEnd, 'String', BaselineEnd);
  2278. end
  2279. else
  2280. set(handles.CheckboxDemean, 'Value', 0);
  2281. set(handles.CheckboxBaselineWholeTrial, 'Value', 0);
  2282. set(handles.TextboxBaselineStart, 'String', []);
  2283. set(handles.TextboxBaselineEnd, 'String', []);
  2284. end
  2285. % Set output handles:
  2286. handles.FTcfg = FTcfg;
  2287. OutputHandles = handles;
  2288. %--- Reset baseline settings & GUI panel: ---%
  2289. %--------------------------------------------%
  2290. function OutputHandles = ResetBaselineSettings(InputHandles)
  2291. handles = InputHandles;
  2292. FTcfg = handles.FTcfg;
  2293. % Reset FTcfg settings:
  2294. FTcfg.Preproc.demean = 'yes';
  2295. FTcfg.Preproc.baselinewindow = [-0.500, -0.050];
  2296. % Reset GUI panel:
  2297. set(handles.CheckboxDemean, 'Value', 1);
  2298. set(handles.CheckboxBaselineWholeTrial, 'Value', 0);
  2299. set(handles.TextboxBaselineStart, 'String', num2str(-0.500, '%1.3f'));
  2300. set(handles.TextboxBaselineEnd, 'String', num2str(-0.050, '%1.3f'));
  2301. % Set output handles:
  2302. handles.FTcfg = FTcfg;
  2303. OutputHandles = handles;
  2304. %========================================%
  2305. % FUNCTIONS FOR GENERAL FILTER SETTINGS: %
  2306. %========================================%
  2307. %--- GUI functions for general filter: ---%
  2308. %-----------------------------------------%
  2309. function CheckboxPassFilter_Callback(hObject, eventdata, handles)
  2310. handles = UpdateGeneralFilterSettings(handles);
  2311. guidata(hObject, handles);
  2312. function PanelPassFilter_SelectionChangeFcn(hObject, eventdata, handles)
  2313. handles = UpdateGeneralFilterSettings(handles);
  2314. guidata(hObject, handles);
  2315. function DropdownPassFilterType_Callback(hObject, eventdata, handles)
  2316. handles = UpdateGeneralFilterSettings(handles);
  2317. guidata(hObject, handles);
  2318. function DropdownPassFilterDir_Callback(hObject, eventdata, handles)
  2319. handles = UpdateGeneralFilterSettings(handles);
  2320. guidata(hObject, handles);
  2321. function DropdownPassFilterInstability_Callback(hObject, eventdata, handles)
  2322. handles = UpdateGeneralFilterSettings(handles);
  2323. guidata(hObject, handles);
  2324. % Textbox for high-pass frequency:
  2325. function TextboxHighpassFreq_Callback(hObject, eventdata, handles)
  2326. Highpass = str2num(get(handles.TextboxHighpassFreq, 'String'));
  2327. Lowpass = str2num(get(handles.TextboxLowpassFreq, 'String'));
  2328. if isempty(Highpass)
  2329. msgbox('Note: High-pass freq. not selected. Default set to 0.5.');
  2330. set(handles.TextboxHighpassFreq, 'String', num2str(0.5));
  2331. end
  2332. if get(handles.ButtonBandpassFilter, 'Value') == 1 && Highpass > Lowpass
  2333. msgbox('Error: High-pass freq. cannot be greater than low-pass.', 'Error:');
  2334. set(handles.TextboxHighpassFreq, 'String', num2str(0.5));
  2335. set(handles.TextboxLowpassFreq, 'String', num2str(55));
  2336. end
  2337. handles = UpdateGeneralFilterSettings(handles);
  2338. guidata(hObject, handles);
  2339. % Textbox for low-pass frequency:
  2340. function TextboxLowpassFreq_Callback(hObject, eventdata, handles)
  2341. Highpass = str2num(get(handles.TextboxHighpassFreq, 'String'));
  2342. Lowpass = str2num(get(handles.TextboxLowpassFreq, 'String'));
  2343. if isempty(Lowpass)
  2344. msgbox('Note: Low-pass freq. not selected. Default set to 55.');
  2345. set(handles.TextboxLowpassFreq, 'String', num2str(55));
  2346. end
  2347. if get(handles.ButtonBandpassFilter, 'Value') == 1 && Lowpass < Highpass
  2348. msgbox('Error: Low-pass freq. cannot be less than high-pass.', 'Error:');
  2349. set(handles.TextboxHighpassFreq, 'String', num2str(0.5));
  2350. set(handles.TextboxLowpassFreq, 'String', num2str(55));
  2351. end
  2352. handles = UpdateGeneralFilterSettings(handles);
  2353. guidata(hObject, handles);
  2354. % Textbox for general filter-order:
  2355. function TextboxPassFilterOrder_Callback(hObject, eventdata, handles)
  2356. if isempty(get(handles.TextboxPassFilterOrder, 'String'))
  2357. msgbox('Note: Filter-order not selected. Default set to 4.');
  2358. set(handles.TextboxPassFilterOrder, 'String', num2str(4));
  2359. end
  2360. handles = UpdateGeneralFilterSettings(handles);
  2361. guidata(hObject, handles);
  2362. %--- Updates general filter settings & GUI panel: ---%
  2363. %----------------------------------------------------%
  2364. function OutputHandles = UpdateGeneralFilterSettings(InputHandles)
  2365. handles = InputHandles;
  2366. FTcfg = handles.FTcfg;
  2367. % Read GUI to update FTcfg:
  2368. if get(handles.CheckboxPassFilter, 'Value') == 1
  2369. HighPass = str2num(get(handles.TextboxHighpassFreq, 'String'));
  2370. LowPass = str2num(get(handles.TextboxLowpassFreq, 'String'));
  2371. if get(handles.ButtonBandpassFilter, 'Value') == 1
  2372. FTcfg.Preproc.bpfilter = 'yes';
  2373. FTcfg.Preproc.hpfilter = 'no';
  2374. FTcfg.Preproc.lpfilter = 'no';
  2375. FTcfg.Preproc.bpfreq = [HighPass, LowPass];
  2376. FTcfg.Preproc.hpfreq = [];
  2377. FTcfg.Preproc.lpfreq = [];
  2378. elseif get(handles.ButtonHighpassFilter, 'Value') == 1
  2379. FTcfg.Preproc.bpfilter = 'no';
  2380. FTcfg.Preproc.hpfilter = 'yes';
  2381. FTcfg.Preproc.lpfilter = 'no';
  2382. FTcfg.Preproc.bpfreq = [];
  2383. FTcfg.Preproc.hpfreq = HighPass;
  2384. FTcfg.Preproc.lpfreq = [];
  2385. elseif get(handles.ButtonLowpassFilter, 'Value') == 1
  2386. FTcfg.Preproc.bpfilter = 'no';
  2387. FTcfg.Preproc.hpfilter = 'no';
  2388. FTcfg.Preproc.lpfilter = 'yes';
  2389. FTcfg.Preproc.bpfreq = [];
  2390. FTcfg.Preproc.hpfreq = [];
  2391. FTcfg.Preproc.lpfreq = LowPass;
  2392. end
  2393. else
  2394. FTcfg.Preproc.bpfilter = 'no';
  2395. FTcfg.Preproc.hpfilter = 'no';
  2396. FTcfg.Preproc.lpfilter = 'no';
  2397. FTcfg.Preproc.bpfreq = [];
  2398. FTcfg.Preproc.hpfreq = [];
  2399. FTcfg.Preproc.lpfreq = [];
  2400. end
  2401. DropdownOptions = get(handles.DropdownPassFilterDir, 'String');
  2402. PassFilterDir = DropdownOptions{get(handles.DropdownPassFilterDir, 'Value')};
  2403. switch PassFilterDir
  2404. case 'Twopass'
  2405. FTcfg.Preproc.bpfiltdir = 'twopass';
  2406. FTcfg.Preproc.hpfiltdir = 'twopass';
  2407. FTcfg.Preproc.lpfiltdir = 'twopass';
  2408. case 'Onepass'
  2409. FTcfg.Preproc.bpfiltdir = 'onepass';
  2410. FTcfg.Preproc.hpfiltdir = 'onepass';
  2411. FTcfg.Preproc.lpfiltdir = 'onepass';
  2412. case 'Onepass-Reverse'
  2413. FTcfg.Preproc.bpfiltdir = 'onepass-reverse';
  2414. FTcfg.Preproc.hpfiltdir = 'onepass-reverse';
  2415. FTcfg.Preproc.lpfiltdir = 'onepass-reverse';
  2416. otherwise
  2417. error('Unrecognized Option'); % error-check
  2418. end
  2419. DropdownOptions = get(handles.DropdownPassFilterType, 'String');
  2420. PassFilterType = DropdownOptions{get(handles.DropdownPassFilterType, 'Value')};
  2421. switch PassFilterType
  2422. case 'Butterworth'
  2423. FTcfg.Preproc.bpfilttype = 'but';
  2424. FTcfg.Preproc.hpfilttype = 'but';
  2425. FTcfg.Preproc.lpfilttype = 'but';
  2426. case 'FIR'
  2427. FTcfg.Preproc.bpfilttype = 'fir';
  2428. FTcfg.Preproc.hpfilttype = 'fir';
  2429. FTcfg.Preproc.lpfilttype = 'fir';
  2430. case 'FIRLS'
  2431. FTcfg.Preproc.bpfilttype = 'firls';
  2432. FTcfg.Preproc.hpfilttype = 'firls';
  2433. FTcfg.Preproc.lpfilttype = 'firls';
  2434. otherwise
  2435. error('Unrecognized Option'); % error-check
  2436. end
  2437. PassFilterOrder = str2num(get(handles.TextboxPassFilterOrder, 'String'));
  2438. switch PassFilterType
  2439. case 'Butterworth'
  2440. FTcfg.Preproc.bpfiltord = PassFilterOrder;
  2441. FTcfg.Preproc.hpfiltord = PassFilterOrder;
  2442. FTcfg.Preproc.lpfiltord = PassFilterOrder;
  2443. case {'FIR', 'FIRLS'}
  2444. FTcfg.Preproc.bpfiltord = [];
  2445. FTcfg.Preproc.hpfiltord = [];
  2446. FTcfg.Preproc.lpfiltord = [];
  2447. end
  2448. DropdownOptions = get(handles.DropdownPassFilterInstability, 'String');
  2449. PassFilterFix = DropdownOptions{get(handles.DropdownPassFilterInstability, 'Value')};
  2450. switch PassFilterFix
  2451. case 'Detect Only'
  2452. FTcfg.Preproc.bpinstabilityfix = 'no';
  2453. FTcfg.Preproc.hpinstabilityfix = 'no';
  2454. FTcfg.Preproc.lpinstabilityfix = 'no';
  2455. case 'Reduce Filter Order'
  2456. FTcfg.Preproc.bpinstabilityfix = 'reduce';
  2457. FTcfg.Preproc.hpinstabilityfix = 'reduce';
  2458. FTcfg.Preproc.lpinstabilityfix = 'reduce';
  2459. case 'Split Filter'
  2460. FTcfg.Preproc.bpinstabilityfix = 'split';
  2461. FTcfg.Preproc.hpinstabilityfix = 'split';
  2462. FTcfg.Preproc.lpinstabilityfix = 'split';
  2463. otherwise
  2464. error('Unrecognized Option'); % error-check
  2465. end
  2466. % Enable/Disable GUI components:
  2467. if get(handles.CheckboxPassFilter, 'Value') == 1
  2468. set(findall(handles.PanelPassFilter, '-property', 'Enable'), 'Enable', 'on');
  2469. if get(handles.ButtonHighpassFilter, 'Value') == 1
  2470. set(handles.TextboxLowpassFreq, 'Enable', 'off');
  2471. set(handles.TextLowpassFreq, 'Enable', 'off'); % Text header
  2472. elseif get(handles.ButtonLowpassFilter, 'Value') ==1
  2473. set(handles.TextboxHighpassFreq, 'Enable', 'off');
  2474. set(handles.TextHighpassFreq, 'Enable', 'off'); % Text header
  2475. end
  2476. if ismember(PassFilterType, {'FIR', 'FIRLS'})
  2477. set(handles.TextboxPassFilterOrder, 'Enable', 'off');
  2478. set(handles.TextPassFilterOrder, 'Enable', 'off'); % Text header
  2479. end
  2480. else
  2481. set(findall(handles.PanelPassFilter, '-property', 'Enable'), 'Enable', 'off');
  2482. set(handles.CheckboxPassFilter, 'Enable', 'on');
  2483. end
  2484. % Lock GUI panel if needed:
  2485. if strcmp(handles.gui.LockPreprocSettings, 'on')
  2486. set(findall(handles.PanelPassFilter, '-property', 'Enable'), 'Enable', 'off');
  2487. end
  2488. % Set output handles:
  2489. handles.FTcfg = FTcfg;
  2490. OutputHandles = handles;
  2491. %--- Load general filter settings & GUI panel: ---%
  2492. %-------------------------------------------------%
  2493. function OutputHandles = LoadGeneralFilterSettings(InputHandles, LoadedMat)
  2494. handles = InputHandles;
  2495. FTcfg = handles.FTcfg;
  2496. % Load FTcfg settings:
  2497. FTcfg.Preproc.bpfilter = LoadedMat.FTcfg.Preproc.bpfilter;
  2498. FTcfg.Preproc.hpfilter = LoadedMat.FTcfg.Preproc.hpfilter;
  2499. FTcfg.Preproc.lpfilter = LoadedMat.FTcfg.Preproc.lpfilter;
  2500. FTcfg.Preproc.bpfreq = LoadedMat.FTcfg.Preproc.bpfreq;
  2501. FTcfg.Preproc.hpfreq = LoadedMat.FTcfg.Preproc.hpfreq;
  2502. FTcfg.Preproc.lpfreq = LoadedMat.FTcfg.Preproc.lpfreq;
  2503. FTcfg.Preproc.bpfiltdir = LoadedMat.FTcfg.Preproc.bpfiltdir;
  2504. FTcfg.Preproc.hpfiltdir = LoadedMat.FTcfg.Preproc.hpfiltdir;
  2505. FTcfg.Preproc.lpfiltdir = LoadedMat.FTcfg.Preproc.lpfiltdir;
  2506. FTcfg.Preproc.bpfilttype = LoadedMat.FTcfg.Preproc.bpfilttype;
  2507. FTcfg.Preproc.hpfilttype = LoadedMat.FTcfg.Preproc.hpfilttype;
  2508. FTcfg.Preproc.lpfilttype = LoadedMat.FTcfg.Preproc.lpfilttype;
  2509. FTcfg.Preproc.bpfiltord = LoadedMat.FTcfg.Preproc.bpfiltord;
  2510. FTcfg.Preproc.hpfiltord = LoadedMat.FTcfg.Preproc.hpfiltord;
  2511. FTcfg.Preproc.lpfiltord = LoadedMat.FTcfg.Preproc.lpfiltord;
  2512. FTcfg.Preproc.bpinstabilityfix = LoadedMat.FTcfg.Preproc.bpinstabilityfix;
  2513. FTcfg.Preproc.hpinstabilityfix = LoadedMat.FTcfg.Preproc.hpinstabilityfix;
  2514. FTcfg.Preproc.lpinstabilityfix = LoadedMat.FTcfg.Preproc.lpinstabilityfix;
  2515. % Load GUI general filter:
  2516. if strcmp(FTcfg.Preproc.bpfilter, 'yes')
  2517. set(handles.CheckboxPassFilter, 'Value', 1);
  2518. set(handles.ButtonBandpassFilter, 'Value', 1);
  2519. set(handles.TextboxHighpassFreq, 'String', num2str(FTcfg.Preproc.bpfreq(1)));
  2520. set(handles.TextboxLowpassFreq, 'String', num2str(FTcfg.Preproc.bpfreq(2)));
  2521. elseif strcmp(FTcfg.Preproc.hpfilter, 'yes')
  2522. set(handles.CheckboxPassFilter, 'Value', 1);
  2523. set(handles.ButtonHighpassFilter, 'Value', 1);
  2524. set(handles.TextboxHighpassFreq, 'String', num2str(FTcfg.Preproc.hpfreq));
  2525. set(handles.TextboxLowpassFreq, 'String', []);
  2526. elseif strcmp(FTcfg.Preproc.lpfilter, 'yes')
  2527. set(handles.CheckboxPassFilter, 'Value', 1);
  2528. set(handles.ButtonLowpassFilter, 'Value', 1);
  2529. set(handles.TextboxHighpassFreq, 'String', []);
  2530. set(handles.TextboxLowpassFreq, 'String', num2str(FTcfg.Preproc.lpfreq));
  2531. elseif strcmp(FTcfg.Preproc.bpfilter, 'no') &&...
  2532. strcmp(FTcfg.Preproc.hpfilter, 'no') &&...
  2533. strcmp(FTcfg.Preproc.lpfilter, 'no')
  2534. set(handles.CheckboxPassFilter, 'Value', 0);
  2535. set(handles.TextboxHighpassFreq, 'String', []);
  2536. set(handles.TextboxLowpassFreq, 'String', []);
  2537. end
  2538. % Load GUI filter direction:
  2539. switch FTcfg.Preproc.bpfiltdir
  2540. case 'twopass'
  2541. PassFilterDir = 'Twopass';
  2542. case 'onepass'
  2543. PassFilterDir = 'Onepass';
  2544. case 'onepass-reverse'
  2545. PassFilterDir = 'Onepass-Reverse';
  2546. otherwise
  2547. error('Unrecognized Option'); % error-check
  2548. end
  2549. DropdownOptions = get(handles.DropdownPassFilterDir, 'String');
  2550. DropdownValue = find(strcmp(DropdownOptions, PassFilterDir));
  2551. set(handles.DropdownPassFilterDir, 'Value', DropdownValue);
  2552. if DropdownValue == 0
  2553. error('Option does not exist in dropdown list.'); % error-check
  2554. end
  2555. % Load GUI filter type:
  2556. switch FTcfg.Preproc.bpfilttype
  2557. case 'but'
  2558. PassFilterType = 'Butterworth';
  2559. set(handles.TextboxPassFilterOrder, 'String', num2str(FTcfg.Preproc.bpfiltord));
  2560. case 'fir'
  2561. PassFilterType = 'FIR';
  2562. set(handles.TextboxPassFilterOrder, 'String', []);
  2563. case 'firls'
  2564. PassFilterType = 'FIRLS';
  2565. set(handles.TextboxPassFilterOrder, 'String', []);
  2566. otherwise
  2567. error('Unrecognized Option'); % error-check
  2568. end
  2569. DropdownOptions = get(handles.DropdownPassFilterType, 'String');
  2570. DropdownValue = find(strcmp(DropdownOptions, PassFilterType));
  2571. set(handles.DropdownPassFilterType, 'Value', DropdownValue);
  2572. if DropdownValue == 0
  2573. error('Option does not exist in dropdown list.'); % error-check
  2574. end
  2575. % Load GUI filter instability:
  2576. switch FTcfg.Preproc.bpinstabilityfix
  2577. case 'no'
  2578. PassFilterFix = 'Detect Only';
  2579. case 'reduce'
  2580. PassFilterFix = 'Reduce Filter Only';
  2581. case 'split'
  2582. PassFilterFix = 'Split Filter';
  2583. otherwise
  2584. error('Unrecognized Option'); % error-check
  2585. end
  2586. DropdownOptions = get(handles.DropdownPassFilterInstability, 'String');
  2587. DropdownValue = find(strcmp(DropdownOptions, PassFilterFix));
  2588. set(handles.DropdownPassFilterInstability, 'Value', DropdownValue);
  2589. if DropdownValue == 0
  2590. error('Option does not exist in dropdown list.'); % error-check
  2591. end
  2592. % Set output handles:
  2593. handles.FTcfg = FTcfg;
  2594. OutputHandles = handles;
  2595. %--- Reset general filter settings & GUI panel: ---%
  2596. %--------------------------------------------------%
  2597. function OutputHandles = ResetGeneralFilterSettings(InputHandles)
  2598. handles = InputHandles;
  2599. FTcfg = handles.FTcfg;
  2600. % Reset FTcfg settings:
  2601. FTcfg.Preproc.bpfilter = 'yes';
  2602. FTcfg.Preproc.hpfilter = 'no';
  2603. FTcfg.Preproc.lpfilter = 'no';
  2604. FTcfg.Preproc.bpfreq = [0.5, 55];
  2605. FTcfg.Preproc.hpfreq = [];
  2606. FTcfg.Preproc.lpfreq = [];
  2607. FTcfg.Preproc.bpfiltdir = 'twopass';
  2608. FTcfg.Preproc.hpfiltdir = 'twopass';
  2609. FTcfg.Preproc.lpfiltdir = 'twopass';
  2610. FTcfg.Preproc.bpfilttype = 'but';
  2611. FTcfg.Preproc.hpfilttype = 'but';
  2612. FTcfg.Preproc.lpfilttype = 'but';
  2613. FTcfg.Preproc.bpfiltord = 4;
  2614. FTcfg.Preproc.hpfiltord = 4;
  2615. FTcfg.Preproc.lpfiltord = 4;
  2616. FTcfg.Preproc.bpinstabilityfix = 'no';
  2617. FTcfg.Preproc.hpinstabilityfix = 'no';
  2618. FTcfg.Preproc.lpinstabilityfix = 'no';
  2619. % Reset GUI panel:
  2620. set(handles.CheckboxPassFilter, 'Value', 1);
  2621. set(handles.ButtonBandpassFilter, 'Value', 1);
  2622. set(handles.ButtonHighpassFilter, 'Value', 0);
  2623. set(handles.ButtonLowpassFilter, 'Value', 0);
  2624. set(handles.TextboxHighpassFreq, 'String', num2str(0.5));
  2625. set(handles.TextboxLowpassFreq, 'String', num2str(55));
  2626. set(handles.DropdownPassFilterDir, 'Value', 1);
  2627. set(handles.DropdownPassFilterType, 'Value', 1);
  2628. set(handles.TextboxPassFilterOrder, 'String', num2str(4));
  2629. set(handles.DropdownPassFilterInstability, 'Value', 1);
  2630. % Set output handles:
  2631. handles.FTcfg = FTcfg;
  2632. OutputHandles = handles;
  2633. %=========================================%
  2634. % FUNCTIONS FOR BANDSTOP FILTER SETTINGS: %
  2635. %=========================================%
  2636. %--- GUI functions for bandstop filter: ---%
  2637. %------------------------------------------%
  2638. function CheckboxBandstopFilter_Callback(hObject, eventdata, handles)
  2639. handles = UpdateBandstopFilterSettings(handles);
  2640. guidata(hObject, handles);
  2641. function DropdownBandstopFilterType_Callback(hObject, eventdata, handles)
  2642. handles = UpdateBandstopFilterSettings(handles);
  2643. guidata(hObject, handles);
  2644. function DropdownBandstopFilterDir_Callback(hObject, eventdata, handles)
  2645. handles = UpdateBandstopFilterSettings(handles);
  2646. guidata(hObject, handles);
  2647. function DropdownBandstopFilterInstability_Callback(hObject, eventdata, handles)
  2648. handles = UpdateBandstopFilterSettings(handles);
  2649. guidata(hObject, handles);
  2650. % Textbox for high-stop frequency:
  2651. function TextboxHighstopFreq_Callback(hObject, eventdata, handles)
  2652. Highstop = str2num(get(handles.TextboxHighstopFreq, 'String'));
  2653. Lowstop = str2num(get(handles.TextboxLowstopFreq, 'String'));
  2654. if isempty(Highstop)
  2655. msgbox('Note: High-stop freq. not specified. Resetting value.');
  2656. set(handles.TextboxHighstopFreq, 'String', num2str(59));
  2657. end
  2658. if Highstop > Lowstop
  2659. msgbox('Error: High-stop freq. cannot be greater than low-stop.', 'Error:');
  2660. set(handles.TextboxHighstopFreq, 'String', num2str(59));
  2661. set(handles.TextboxLowstopFreq, 'String', num2str(61));
  2662. end
  2663. handles = UpdateBandstopFilterSettings(handles);
  2664. guidata(hObject, handles);
  2665. % Textbox for low-stop frequency:
  2666. function TextboxLowstopFreq_Callback(hObject, eventdata, handles)
  2667. Highstop = str2num(get(handles.TextboxHighstopFreq, 'String'));
  2668. Lowstop = str2num(get(handles.TextboxLowstopFreq, 'String'));
  2669. if isempty(Lowstop)
  2670. msgbox('Note: Low-stop freq. not specified. Resetting value.');
  2671. set(handles.TextboxLowstopFreq, 'String', num2str(61));
  2672. end
  2673. if Lowstop < Highstop
  2674. msgbox('Error: Low-stop freq. cannot be less than high-stop.', 'Error:');
  2675. set(handles.TextboxHighstopFreq, 'String', num2str(59));
  2676. set(handles.TextboxLowstopFreq, 'String', num2str(61));
  2677. end
  2678. handles = UpdateBandstopFilterSettings(handles);
  2679. guidata(hObject, handles);
  2680. % Textbox for stop-filter order:
  2681. function TextboxBandstopFilterOrder_Callback(hObject, eventdata, handles)
  2682. if isempty(get(handles.TextboxBandstopFilterOrder, 'String'))
  2683. msgbox('Note: Bandstop filter order not specified. Default set to 4.');
  2684. set(handles.TextboxBandstopFilterOrder, 'String', num2str(4));
  2685. end
  2686. handles = UpdateBandstopFilterSettings(handles);
  2687. guidata(hObject, handles);
  2688. %--- Updates bandstop filter settings & GUI panel: ---%
  2689. %-----------------------------------------------------%
  2690. function OutputHandles = UpdateBandstopFilterSettings(InputHandles)
  2691. handles = InputHandles;
  2692. FTcfg = handles.FTcfg;
  2693. % Read GUI to update FTcfg:
  2694. if get(handles.CheckboxBandstopFilter, 'Value') == 1
  2695. FTcfg.Preproc.bsfilter = 'yes';
  2696. FTcfg.Preproc.bsfreq = [str2num(get(handles.TextboxHighstopFreq, 'String')),...
  2697. str2num(get(handles.TextboxLowstopFreq, 'String'))];
  2698. else
  2699. FTcfg.Preproc.bsfilter = 'no';
  2700. FTcfg.Preproc.bsfreq = [];
  2701. end
  2702. DropdownOptions = get(handles.DropdownBandstopFilterDir, 'String');
  2703. BandstopFilterDir = DropdownOptions{get(handles.DropdownBandstopFilterDir, 'Value')};
  2704. switch BandstopFilterDir
  2705. case 'Twopass'
  2706. FTcfg.Preproc.bsfiltdir = 'twopass';
  2707. case 'Onepass'
  2708. FTcfg.Preproc.bsfiltdir = 'onepass';
  2709. case 'Onepass-Reverse'
  2710. FTcfg.Preproc.bsfiltdir = 'onepass-reverse';
  2711. otherwise
  2712. error('Unrecognized Option'); % error-check
  2713. end
  2714. DropdownOptions = get(handles.DropdownBandstopFilterType, 'String');
  2715. BandstopFilterType = DropdownOptions{get(handles.DropdownBandstopFilterType, 'Value')};
  2716. switch BandstopFilterType
  2717. case 'Butterworth'
  2718. FTcfg.Preproc.bsfilttype = 'but';
  2719. case 'FIR'
  2720. FTcfg.Preproc.bsfilttype = 'fir';
  2721. case 'FIRLS'
  2722. FTcfg.Preproc.bsfilttype = 'firls';
  2723. otherwise
  2724. error('Unrecognized Option'); % error-check
  2725. end
  2726. BandstopFilterOrder = str2num(get(handles.TextboxBandstopFilterOrder, 'String'));
  2727. switch BandstopFilterType
  2728. case 'Butterworth'
  2729. FTcfg.Preproc.bsfiltord = BandstopFilterOrder;
  2730. case {'FIR', 'FIRLS'}
  2731. FTcfg.Preproc.bsfiltord = [];
  2732. end
  2733. DropdownOptions = get(handles.DropdownBandstopFilterInstability, 'String');
  2734. BandstopFilterFix = DropdownOptions{get(handles.DropdownBandstopFilterInstability, 'Value')};
  2735. switch BandstopFilterFix
  2736. case 'Detect Only'
  2737. FTcfg.Preproc.bsinstabilityfix = 'no';
  2738. case 'Reduce Filter Order'
  2739. FTcfg.Preproc.bsinstabilityfix = 'reduce';
  2740. case 'Split Filter'
  2741. FTcfg.Preproc.bsinstabilityfix = 'split';
  2742. otherwise
  2743. error('Unrecognized Option'); % error-check
  2744. end
  2745. % Enable/Disable GUI components:
  2746. if get(handles.CheckboxBandstopFilter, 'Value') == 1
  2747. set(findall(handles.PanelBandstopFilter, '-property', 'Enable'), 'Enable', 'on');
  2748. if ismember(BandstopFilterType, {'FIR', 'FIRLS'})
  2749. set(handles.TextboxBandstopFilterOrder, 'Enable', 'off');
  2750. set(handles.TextBandstopFilterOrder, 'Enable', 'off'); % Text header
  2751. end
  2752. else
  2753. set(findall(handles.PanelBandstopFilter, '-property', 'Enable'), 'Enable', 'off');
  2754. set(handles.CheckboxBandstopFilter, 'Enable', 'on');
  2755. end
  2756. % Lock GUI panel if needed:
  2757. if strcmp(handles.gui.LockPreprocSettings, 'on')
  2758. set(findall(handles.PanelBandstopFilter, '-property', 'Enable'), 'Enable', 'off');
  2759. end
  2760. % Set output handles:
  2761. handles.FTcfg = FTcfg;
  2762. OutputHandles = handles;
  2763. %--- Load bandstop filter settings & GUI panel: ---%
  2764. %--------------------------------------------------%
  2765. function OutputHandles = LoadBandstopFilterSettings(InputHandles, LoadedMat)
  2766. handles = InputHandles;
  2767. FTcfg = handles.FTcfg;
  2768. % Load FTcfg settings:
  2769. FTcfg.Preproc.bsfilter = LoadedMat.FTcfg.Preproc.bsfilter;
  2770. FTcfg.Preproc.bsfreq = LoadedMat.FTcfg.Preproc.bsfreq;
  2771. FTcfg.Preproc.bsfiltdir = LoadedMat.FTcfg.Preproc.bsfiltdir;
  2772. FTcfg.Preproc.bsfilttype = LoadedMat.FTcfg.Preproc.bsfilttype;
  2773. FTcfg.Preproc.bsfiltord = LoadedMat.FTcfg.Preproc.bsfiltord;
  2774. FTcfg.Preproc.bsinstabilityfix = LoadedMat.FTcfg.Preproc.bsinstabilityfix;
  2775. % Load GUI components:
  2776. if strcmp(FTcfg.Preproc.bsfilter, 'yes')
  2777. set(handles.CheckboxBandstopFilter, 'Value', 1);
  2778. set(handles.TextboxHighstopFreq, 'String', num2str(FTcfg.Preproc.bsfreq(1)));
  2779. set(handles.TextboxLowstopFreq, 'String', num2str(FTcfg.Preproc.bsfreq(2)));
  2780. else
  2781. set(handles.CheckboxBandstopFilter, 'Value', 0);
  2782. set(handles.TextboxHighstopFreq, 'String', []);
  2783. set(handles.TextboxLowstopFreq, 'String', []);
  2784. end
  2785. % Load GUI filter direction:
  2786. switch FTcfg.Preproc.bsfiltdir
  2787. case 'twopass'
  2788. BandstopFilterDir = 'Twopass';
  2789. case 'onepass'
  2790. BandstopFilterDir = 'Onepass';
  2791. case 'onepass-reverse'
  2792. BandstopFilterDir = 'Onepass-Reverse';
  2793. otherwise
  2794. error('Unrecognized Option'); % error-check
  2795. end
  2796. DropdownOptions = get(handles.DropdownBandstopFilterDir, 'String');
  2797. DropdownValue = find(strcmp(DropdownOptions, BandstopFilterDir));
  2798. set(handles.DropdownBandstopFilterDir, 'Value', DropdownValue);
  2799. if DropdownValue == 0
  2800. error('Option does not exist in dropdown list.'); % error-check
  2801. end
  2802. % Load GUI filter type:
  2803. switch FTcfg.Preproc.bsfilttype
  2804. case 'but'
  2805. BandstopFilterType = 'Butterworth';
  2806. set(handles.TextboxBandstopFilterOrder, 'String', num2str(FTcfg.Preproc.bsfiltord));
  2807. case 'fir'
  2808. BandstopFilterType = 'FIR';
  2809. set(handles.TextboxBandstopFilterOrder, 'String', []);
  2810. case 'firls'
  2811. BandstopFilterType = 'FIRLS';
  2812. set(handles.TextboxBandstopFilterOrder, 'String', []);
  2813. otherwise
  2814. error('Unrecognized Option'); % error-check
  2815. end
  2816. DropdownOptions = get(handles.DropdownBandstopFilterType, 'String');
  2817. DropdownValue = find(strcmp(DropdownOptions, BandstopFilterType));
  2818. set(handles.DropdownBandstopFilterType, 'Value', DropdownValue);
  2819. if DropdownValue == 0
  2820. error('Option does not exist in dropdown list.'); % error-check
  2821. end
  2822. % Load GUI instability fix:
  2823. switch FTcfg.Preproc.bsinstabilityfix
  2824. case 'no'
  2825. BandstopFilterFix = 'Detect Only';
  2826. case 'reduce'
  2827. BandstopFilterFix = 'Reduce Filter Order';
  2828. case 'split'
  2829. BandstopFilterFix = 'Split Filter';
  2830. otherwise
  2831. error('Unrecognized Option'); % error-check
  2832. end
  2833. DropdownOptions = get(handles.DropdownBandstopFilterInstability, 'String');
  2834. DropdownValue = find(strcmp(DropdownOptions, BandstopFilterFix));
  2835. set(handles.DropdownBandstopFilterInstability, 'Value', DropdownValue);
  2836. if DropdownValue == 0
  2837. error('Option does not exist in dropdown list.'); % error-check
  2838. end
  2839. % Set output handles:
  2840. handles.FTcfg = FTcfg;
  2841. OutputHandles = handles;
  2842. %--- Reset bandstop filter settings & GUI panel: ---%
  2843. %---------------------------------------------------%
  2844. function OutputHandles = ResetBandstopFilterSettings(InputHandles)
  2845. handles = InputHandles;
  2846. FTcfg = handles.FTcfg;
  2847. % Reset FTcfg settings:
  2848. FTcfg.Preproc.bsfilter = 'no';
  2849. FTcfg.Preproc.bsfreq = [];
  2850. FTcfg.Preproc.bsfiltdir = 'twopass';
  2851. FTcfg.Preproc.bsfilttype = 'but';
  2852. FTcfg.Preproc.bsfiltord = 4;
  2853. FTcfg.Preproc.bsinstabilityfix = 'no';
  2854. % Reset GUI panel:
  2855. set(handles.CheckboxBandstopFilter, 'Value', 0);
  2856. set(handles.TextboxHighstopFreq, 'String', []);
  2857. set(handles.TextboxLowstopFreq, 'String', []);
  2858. set(handles.DropdownBandstopFilterDir, 'Value', 1);
  2859. set(handles.DropdownBandstopFilterType, 'Value', 1);
  2860. set(handles.TextboxBandstopFilterOrder, 'String', num2str(4));
  2861. set(handles.DropdownBandstopFilterInstability, 'Value', 1);
  2862. % Set output handles:
  2863. handles.FTcfg = FTcfg;
  2864. OutputHandles = handles;
  2865. %====================================%
  2866. % FUNCTIONS FOR DFT FILTER SETTINGS: %
  2867. %====================================%
  2868. %--- GUI functions for DFT filter: ---%
  2869. %-------------------------------------%
  2870. function CheckboxDFT_Callback(hObject, eventdata, handles)
  2871. handles = UpdateDFTFilterSettings(handles);
  2872. guidata(hObject, handles);
  2873. function PanelDFT_SelectionChangeFcn(hObject, eventdata, handles)
  2874. handles = UpdateDFTFilterSettings(handles);
  2875. guidata(hObject, handles);
  2876. function TextboxDFTcustom_Callback(hObject, eventdata, handles)
  2877. if isempty(get(handles.TextboxDFTcustom, 'String'))
  2878. msgbox('Note: Custom DFT filter frequency not specified. Set to default value.')
  2879. set(handles.TextboxDFTcustom, 'String', '60, 120, 180');
  2880. end
  2881. handles = UpdateDFTFilterSettings(handles);
  2882. guidata(hObject, handles);
  2883. %--- Updates DFT filter settings & GUI panel: ---%
  2884. %------------------------------------------------%
  2885. function OutputHandles = UpdateDFTFilterSettings(InputHandles)
  2886. handles = InputHandles;
  2887. FTcfg = handles.FTcfg;
  2888. % Read GUI to update FTcfg:
  2889. if get(handles.CheckboxDFT, 'Value') == 1
  2890. FTcfg.Preproc.dftfilter = 'yes';
  2891. if get(handles.ButtonDFTdefault, 'Value') == 1
  2892. FTcfg.Preproc.dftfreq = [60, 120, 180];
  2893. elseif get(handles.ButtonDFTeuropean, 'Value') == 1
  2894. FTcfg.Preproc.dftfreq = [50, 100, 150];
  2895. elseif get(handles.ButtonDFTcustom, 'Value') == 1
  2896. FTcfg.Preproc.dftfreq = [str2num(get(handles.TextboxDFTcustom, 'String'))];
  2897. end
  2898. else
  2899. FTcfg.Preproc.dftfilter = 'no';
  2900. FTcfg.Preproc.dftfreq = [];
  2901. end
  2902. % Enable/Disable GUI components:
  2903. if get(handles.CheckboxDFT, 'Value') == 1
  2904. set(findall(handles.PanelDFT, '-property', 'Enable'), 'Enable', 'on');
  2905. if get(handles.ButtonDFTcustom, 'Value') == 0
  2906. set(handles.TextboxDFTcustom, 'Enable', 'off');
  2907. end
  2908. else
  2909. set(findall(handles.PanelDFT, '-property', 'Enable'), 'Enable', 'off');
  2910. set(handles.CheckboxDFT, 'Enable', 'on');
  2911. end
  2912. % Lock GUI panel if needed:
  2913. if strcmp(handles.gui.LockPreprocSettings, 'on')
  2914. set(findall(handles.PanelDFT, '-property', 'Enable'), 'Enable', 'off');
  2915. end
  2916. % Set output handles:
  2917. handles.FTcfg = FTcfg;
  2918. OutputHandles = handles;
  2919. %--- Load DFT filter settings & GUI panel: ---%
  2920. %---------------------------------------------%
  2921. function OutputHandles = LoadDFTFilterSettings(InputHandles, LoadedMat)
  2922. handles = InputHandles;
  2923. FTcfg = handles.FTcfg;
  2924. % Load FTcfg settings:
  2925. FTcfg.Preproc.dftfilter = LoadedMat.FTcfg.Preproc.dftfilter;
  2926. FTcfg.Preproc.dftfreq = LoadedMat.FTcfg.Preproc.dftfreq;
  2927. % Load GUI panel:
  2928. if strcmp(FTcfg.Preproc.dftfilter, 'yes')
  2929. set(handles.CheckboxDFT, 'Value', 1);
  2930. if isequal(FTcfg.Preproc.dftfreq, [60, 120, 180])
  2931. set(handles.ButtonDFTdefault, 'Value', 1);
  2932. set(handles.TextboxDFTcustom, 'String', []);
  2933. elseif isequal(FTcfg.Preproc.dftfreq, [50, 100, 150])
  2934. set(handles.ButtonDFTeuropean, 'Value', 1);
  2935. set(handles.TextboxDFTcustom, 'String', []);
  2936. else
  2937. set(handles.ButtonDFTcustom, 'Value', 1);
  2938. set(handles.TextboxDFTcustom, 'String', num2str(FTcfg.Preproc.dftfreq));
  2939. end
  2940. else
  2941. set(handles.CheckboxDFT, 'Value', 0);
  2942. set(handles.ButtonDFTdefault, 'Value', 1);
  2943. set(handles.ButtonDFTeuropean, 'Value', 0);
  2944. set(handles.ButtonDFTcustom, 'Value', 0);
  2945. set(handles.TextboxDFTcustom, 'String', []);
  2946. end
  2947. % Set output handles:
  2948. handles.FTcfg = FTcfg;
  2949. OutputHandles = handles;
  2950. %--- Reset DFT filter settings & GUI panel: ---%
  2951. %----------------------------------------------%
  2952. function OutputHandles = ResetDFTFilterSettings(InputHandles)
  2953. handles = InputHandles;
  2954. FTcfg = handles.FTcfg;
  2955. % Reset FTcfg settings:
  2956. FTcfg.Preproc.dftfilter = 'yes';
  2957. FTcfg.Preproc.dftfreq = [60, 120, 180];
  2958. % Reset GUI panel:
  2959. set(handles.CheckboxDFT, 'Value', 1);
  2960. set(handles.ButtonDFTdefault, 'Value', 1);
  2961. set(handles.ButtonDFTeuropean, 'Value', 0);
  2962. set(handles.ButtonDFTcustom, 'Value', 0);
  2963. set(handles.TextboxDFTcustom, 'String', []);
  2964. % Set output handles:
  2965. handles.FTcfg = FTcfg;
  2966. OutputHandles = handles;
  2967. %=======================================%
  2968. % FUNCTIONS FOR MEDIAN FILTER SETTINGS: %
  2969. %=======================================%
  2970. %--- GUI functions for median filter: ---%
  2971. %----------------------------------------%
  2972. function CheckboxMedianFilter_Callback(hObject, eventdata, handles)
  2973. handles = UpdateMedianFilterSettings(handles);
  2974. guidata(hObject, handles);
  2975. function TextboxMedianFilterOrder_Callback(hObject, eventdata, handles)
  2976. if isempty(get(handles.TextboxMedianFilterOrder, 'String'))
  2977. msgbox('Note: Median filter order not set. Default set to 9.');
  2978. set(handles.TextboxMedianFilterOrder, 'String', num2str(9));
  2979. end
  2980. handles = UpdateMedianFilterSettings(handles);
  2981. guidata(hObject, handles);
  2982. %--- Updates median filter settings & GUI panel: ---%
  2983. %---------------------------------------------------%
  2984. function OutputHandles = UpdateMedianFilterSettings(InputHandles)
  2985. handles = InputHandles;
  2986. FTcfg = handles.FTcfg;
  2987. % Read GUI to update FTcfg:
  2988. if get(handles.CheckboxMedianFilter, 'Value') == 1
  2989. FTcfg.Preproc.medianfilter = 'yes';
  2990. FTcfg.Preproc.medianfiltord = str2num(get(handles.TextboxMedianFilterOrder, 'String'));
  2991. else
  2992. FTcfg.Preproc.medianfilter = 'no';
  2993. FTcfg.Preproc.medianfiltord = [];
  2994. end
  2995. % Enable/Disable GUI components:
  2996. if get(handles.CheckboxMedianFilter, 'Value') == 1
  2997. set(findall(handles.PanelMedianFilter, '-property', 'Enable'), 'Enable', 'on');
  2998. else
  2999. set(findall(handles.PanelMedianFilter, '-property', 'Enable'), 'Enable', 'off');
  3000. set(handles.CheckboxMedianFilter, 'Enable', 'on');
  3001. end
  3002. % Lock GUI panel if needed:
  3003. if strcmp(handles.gui.LockPreprocSettings, 'on')
  3004. set(findall(handles.PanelMedianFilter, '-property', 'Enable'), 'Enable', 'off');
  3005. end
  3006. % Set output handles:
  3007. handles.FTcfg = FTcfg;
  3008. OutputHandles = handles;
  3009. %--- Load median filter settings & GUI panel: ---%
  3010. %------------------------------------------------%
  3011. function OutputHandles = LoadMedianFilterSettings(InputHandles, LoadedMat)
  3012. handles = InputHandles;
  3013. FTcfg = handles.FTcfg;
  3014. % Load FTcfg settings:
  3015. FTcfg.Preproc.medianfilter = LoadedMat.FTcfg.Preproc.medianfilter;
  3016. FTcfg.Preproc.medianfiltord = LoadedMat.FTcfg.Preproc.medianfiltord;
  3017. % Load GUI panel:
  3018. if strcmp(FTcfg.Preproc.medianfilter, 'yes')
  3019. set(handles.CheckboxMedianFilter, 'Value', 1);
  3020. set(handles.TextboxMedianFilterOrder, 'String', num2str(FTcfg.Preproc.medianfiltord));
  3021. else
  3022. set(handles.CheckboxMedianFilter, 'Value', 0);
  3023. set(handles.TextboxMedianFilterOrder, 'String', []);
  3024. end
  3025. % Set output handles:
  3026. handles.FTcfg = FTcfg;
  3027. OutputHandles = handles;
  3028. %--- Reset DFT filter settings & GUI panel: ---%
  3029. %----------------------------------------------%
  3030. function OutputHandles = ResetMedianFilterSettings(InputHandles)
  3031. handles = InputHandles;
  3032. FTcfg = handles.FTcfg;
  3033. % Reset FTcfg settings:
  3034. FTcfg.Preproc.medianfilter = 'no';
  3035. FTcfg.Preproc.medianfiltord = 9;
  3036. % Reset GUI panel:
  3037. set(handles.CheckboxMedianFilter, 'Value', 0);
  3038. set(handles.TextboxMedianFilterOrder, 'String', num2str(9));
  3039. % Set output handles:
  3040. handles.FTcfg = FTcfg;
  3041. OutputHandles = handles;
  3042. %=======================================%
  3043. % FUNCTIONS FOR TREND REMOVAL SETTINGS: %
  3044. %=======================================%
  3045. %--- GUI functions for trend removal: ---%
  3046. %----------------------------------------%
  3047. function CheckboxDetrend_Callback(hObject, eventdata, handles)
  3048. handles = UpdateDetrendSettings(handles);
  3049. guidata(hObject, handles);
  3050. function CheckboxPolyremoval_Callback(hObject, eventdata, handles)
  3051. handles = UpdateDetrendSettings(handles);
  3052. guidata(hObject, handles);
  3053. function TextboxPolyremovalOrder_Callback(hObject, eventdata, handles)
  3054. if isempty(get(handles.TextboxPolyremovalOrder, 'String'))
  3055. msgbox('Note: Polyremoval order not specified. Default set to 2.');
  3056. set(handles.TextboxPolyremovalOrder, 'String', num2str(2));
  3057. end
  3058. handles = UpdateDetrendSettings(handles);
  3059. guidata(hObject, handles);
  3060. %--- Updates trend removal settings & GUI panel: ---%
  3061. %---------------------------------------------------%
  3062. function OutputHandles = UpdateDetrendSettings(InputHandles)
  3063. handles = InputHandles;
  3064. FTcfg = handles.FTcfg;
  3065. % Read GUI to update FTcfg:
  3066. if get(handles.CheckboxDetrend, 'Value') == 1
  3067. FTcfg.Preproc.detrend = 'yes';
  3068. else
  3069. FTcfg.Preproc.detrend = 'no';
  3070. end
  3071. if get(handles.CheckboxPolyremoval, 'Value') == 1
  3072. FTcfg.Preproc.polyremoval = 'yes';
  3073. FTcfg.Preproc.polyorder = str2num(get(handles.TextboxPolyremovalOrder, 'String'));
  3074. else
  3075. FTcfg.Preproc.polyremoval = 'no';
  3076. FTcfg.Preproc.polyorder = [];
  3077. end
  3078. % Enable/Disable GUI components:
  3079. set(findall(handles.PanelDetrend, '-property', 'Enable'), 'Enable', 'on');
  3080. if get(handles.CheckboxPolyremoval, 'Value') == 0
  3081. set(handles.TextboxPolyremovalOrder, 'Enable', 'off');
  3082. set(handles.TextPolyremovalOrder, 'Enable', 'off');
  3083. end
  3084. % Lock GUI panel if needed:
  3085. if strcmp(handles.gui.LockPreprocSettings, 'on')
  3086. set(findall(handles.PanelDetrend, '-property', 'Enable'), 'Enable', 'off');
  3087. end
  3088. % Set output handles:
  3089. handles.FTcfg = FTcfg;
  3090. OutputHandles = handles;
  3091. %--- Load trend removal settings & GUI panel: ---%
  3092. %------------------------------------------------%
  3093. function OutputHandles = LoadDetrendSettings(InputHandles, LoadedMat)
  3094. handles = InputHandles;
  3095. FTcfg = handles.FTcfg;
  3096. % Load FTcfg settings:
  3097. FTcfg.Preproc.detrend = LoadedMat.FTcfg.Preproc.detrend;
  3098. FTcfg.Preproc.polyremoval = LoadedMat.FTcfg.Preproc.polyremoval;
  3099. FTcfg.Preproc.polyorder = LoadedMat.FTcfg.Preproc.polyorder;
  3100. % Load GUI panel:
  3101. if strcmp(FTcfg.Preproc.detrend, 'yes')
  3102. set(handles.CheckboxDetrend, 'Value', 1);
  3103. else
  3104. set(handles.CheckboxDetrend, 'Value', 0);
  3105. end
  3106. if strcmp(FTcfg.Preproc.polyremoval, 'yes')
  3107. set(handles.CheckboxPolyremoval, 'Value', 1);
  3108. set(handles.TextboxPolyremovalOrder, 'String', num2str(FTcfg.Preproc.polyorder));
  3109. else
  3110. set(handles.CheckboxPolyremoval, 'Value', 0);
  3111. set(handles.TextboxPolyremovalOrder, 'String', []);
  3112. end
  3113. % Set output handles:
  3114. handles.FTcfg = FTcfg;
  3115. OutputHandles = handles;
  3116. %--- Reset trend removal settings & GUI panel: ---%
  3117. %-------------------------------------------------%
  3118. function OutputHandles = ResetDetrendSettings(InputHandles)
  3119. handles = InputHandles;
  3120. FTcfg = handles.FTcfg;
  3121. % Reset FTcfg settings:
  3122. FTcfg.Preproc.detrend = 'no';
  3123. FTcfg.Preproc.polyremoval = 'no';
  3124. FTcfg.Preproc.polyorder = 2;
  3125. % Reset GUI panel:
  3126. set(handles.CheckboxDetrend, 'Value', 0);
  3127. set(handles.CheckboxPolyremoval, 'Value', 0);
  3128. set(handles.TextboxPolyremovalOrder, 'String', num2str(2));
  3129. % Set output handles:
  3130. handles.FTcfg = FTcfg;
  3131. OutputHandles = handles;
  3132. %==========================================%
  3133. % FUNCTIONS FOR OTHER ADV. SETTINGS PANEL: %
  3134. %==========================================%
  3135. %--- GUI functions for other adv. settings: ---%
  3136. %----------------------------------------------%
  3137. function CheckboxGradCorrCTF_Callback(hObject, eventdata, handles)
  3138. handles = UpdateOtherAdvSettings(handles);
  3139. guidata(hObject, handles);
  3140. function DropdownGradCorrCTF_Callback(hObject, eventdata, handles)
  3141. handles = UpdateOtherAdvSettings(handles);
  3142. guidata(hObject, handles);
  3143. function CheckboxHilbert_Callback(hObject, eventdata, handles)
  3144. handles = UpdateOtherAdvSettings(handles);
  3145. guidata(hObject, handles);
  3146. function DropdownHilbert_Callback(hObject, eventdata, handles)
  3147. handles = UpdateOtherAdvSettings(handles);
  3148. guidata(hObject, handles);
  3149. function CheckboxRectify_Callback(hObject, eventdata, handles)
  3150. handles = UpdateOtherAdvSettings(handles);
  3151. guidata(hObject, handles);
  3152. function CheckboxDerivative_Callback(hObject, eventdata, handles)
  3153. handles = UpdateOtherAdvSettings(handles);
  3154. guidata(hObject, handles);
  3155. %--- Updates other adv. settings & GUI panel: ---%
  3156. %---------------------------------------------------%
  3157. function OutputHandles = UpdateOtherAdvSettings(InputHandles)
  3158. handles = InputHandles;
  3159. FTcfg = handles.FTcfg;
  3160. % Check if options valid:
  3161. if get(handles.CheckboxGradCorrCTF, 'Value') == 1 &&...
  3162. ~strcmp(handles.gui.DataFiletype, 'CTFds')
  3163. msgbox('Warning: CTF gradient correction is disabled for filetype.', 'Warning:');
  3164. set(handles.CheckboxGradCorrCTF, 'Value', 0);
  3165. end
  3166. if get(handles.CheckboxHilbert, 'Value') == 1 &&...
  3167. get(handles.ButtonBandpassFilter, 'Value') == 0
  3168. msgbox('Warning: Hilbert transform must be run with bandpass filter.', 'Warning:');
  3169. set(handles.CheckboxHilbert, 'Value', 0);
  3170. end
  3171. if get(handles.CheckboxRectify, 'Value') == 1 &&...
  3172. get(handles.CheckboxHilbert, 'Value') == 1
  3173. msgbox('Warning: Rectify data cannot be run with Hilbert transform.', 'Warning:');
  3174. set(handles.CheckboxRectify, 'Value', 0);
  3175. end
  3176. % Read GUI to update FTcfg:
  3177. if get(handles.CheckboxGradCorrCTF, 'Value') == 1
  3178. DropdownOptions = get(handles.DropdownGradCorrCTF, 'String');
  3179. GradCorrType = DropdownOptions{get(handles.DropdownGradCorrCTF, 'Value')};
  3180. switch GradCorrType
  3181. case 'First-Order'
  3182. FTcfg.GradCorrectCTF.gradient = 'G1BR';
  3183. case 'Second-Order'
  3184. FTcfg.GradCorrectCTF.gradient = 'G2BR';
  3185. case 'Third-Order'
  3186. FTcfg.GradCorrectCTF.gradient = 'G3BR';
  3187. otherwise
  3188. error('Unrecognized Option'); % error-check
  3189. end
  3190. FTcfg.GradCorrectCTF.trials = 'all';
  3191. else
  3192. FTcfg.GradCorrectCTF = [];
  3193. FTcfg.GradCorrectCTF = 'none';
  3194. end
  3195. if get(handles.CheckboxHilbert, 'Value') == 1
  3196. DropdownOptions = get(handles.DropdownHilbert, 'String');
  3197. HilbertType = DropdownOptions{get(handles.DropdownHilbert, 'Value')};
  3198. FTcfg.Preproc.hilbert = HilbertType;
  3199. else
  3200. FTcfg.Preproc.hilbert = 'no';
  3201. end
  3202. if get(handles.CheckboxRectify, 'Value') == 1
  3203. FTcfg.Preproc.rectify = 'yes';
  3204. else
  3205. FTcfg.Preproc.rectify = 'no';
  3206. end
  3207. if get(handles.CheckboxDerivative, 'Value') == 1
  3208. FTcfg.Preproc.derivative = 'yes';
  3209. else
  3210. FTcfg.Preproc.derivative = 'no';
  3211. end
  3212. % Enable/Disable GUI components:
  3213. set(findall(handles.PanelOtherAdvOptions, '-property', 'Enable'), 'Enable', 'on');
  3214. if strcmp(handles.gui.DataFiletype, 'Fieldtrip')
  3215. set(handles.CheckboxGradCorrCTF, 'Enable', 'off');
  3216. set(handles.DropdownGradCorrCTF, 'Enable', 'off');
  3217. end
  3218. if get(handles.CheckboxGradCorrCTF, 'Value') == 0
  3219. set(handles.DropdownGradCorrCTF, 'Enable', 'off');
  3220. end
  3221. if get(handles.CheckboxHilbert, 'Value') == 0
  3222. set(handles.DropdownHilbert, 'Enable', 'off');
  3223. end
  3224. % Lock GUI panel if needed:
  3225. if strcmp(handles.gui.LockPreprocSettings, 'on')
  3226. set(findall(handles.PanelOtherAdvOptions, '-property', 'Enable'), 'Enable', 'off');
  3227. end
  3228. % Set output handles:
  3229. handles.FTcfg = FTcfg;
  3230. OutputHandles = handles;
  3231. %--- Load other adv. settings & GUI panel: ---%
  3232. %---------------------------------------------%
  3233. function OutputHandles = LoadOtherAdvSettings(InputHandles, LoadedMat)
  3234. handles = InputHandles;
  3235. FTcfg = handles.FTcfg;
  3236. % Load FTcfg settings:
  3237. FTcfg.GradCorrectCTF = LoadedMat.FTcfg.GradCorrectCTF;
  3238. FTcfg.Preproc.hilbert = LoadedMat.FTcfg.Preproc.hilbert;
  3239. FTcfg.Preproc.rectify = LoadedMat.FTcfg.Preproc.rectify;
  3240. FTcfg.Preproc.derivative = LoadedMat.FTcfg.Preproc.derivative;
  3241. % Load GUI panel:
  3242. if ~strcmp(FTcfg.GradCorrectCTF, 'none')
  3243. set(handles.CheckboxGradCorrCTF, 'Value', 1);
  3244. switch FTcfg.GradCorrectCTF.gradient
  3245. case 'G1BR'
  3246. GradCorrType = 'First-Order';
  3247. case 'G2BR'
  3248. GradCorrType = 'Second-Order';
  3249. case 'G3BR'
  3250. GradCorrType = 'Third-Order';
  3251. otherwise
  3252. error('Unrecognized Option'); % error-check
  3253. end
  3254. DropdownOptions = get(handles.DropdownGradCorrCTF, 'String');
  3255. DropdownValue = find(strcmp(DropdownOptions, GradCorrType));
  3256. set(handles.DropdownGradCorrCTF, 'Value', DropdownValue);
  3257. if DropdownValue == 0
  3258. error('Option does not exist in dropdown list.'); % error-check
  3259. end
  3260. else
  3261. set(handles.CheckboxGradCorrCTF, 'Value', 0);
  3262. set(handles.DropdownGradCorrCTF, 'Value', 3);
  3263. end
  3264. if strcmp(FTcfg.Preproc.hilbert, 'yes')
  3265. set(handles.CheckboxHilbert, 'Value', 1);
  3266. DropdownOptions = get(handles.DropdownHilbert, 'String')
  3267. DropdownValue = find(strcmp(DropdownOptions, cfg.Preproc.hilbert));
  3268. set(handles.DropdownHilbert, 'Value', DropdownValue);
  3269. else
  3270. set(handles.CheckboxHilbert, 'Value', 0);
  3271. end
  3272. if strcmp(FTcfg.Preproc.rectify, 'yes')
  3273. set(handles.CheckboxRectify, 'Value', 1);
  3274. else
  3275. set(handles.CheckboxRectify, 'Value', 0);
  3276. end
  3277. if strcmp(FTcfg.Preproc.derivative, 'yes')
  3278. set(handles.CheckboxDerivative, 'Value', 1);
  3279. else
  3280. set(handles.CheckboxDerivative, 'Value', 0);
  3281. end
  3282. % Set output handles:
  3283. handles.FTcfg = FTcfg;
  3284. OutputHandles = handles;
  3285. %--- Reset other adv. settings & GUI panel: ---%
  3286. %----------------------------------------------%
  3287. function OutputHandles = ResetOtherAdvSettings(InputHandles)
  3288. handles = InputHandles;
  3289. FTcfg = handles.FTcfg;
  3290. % Reset FTcfg settings:
  3291. FTcfg.GradCorrectCTF.gradient = 'G3BR';
  3292. FTcfg.GradCorrectCTF.trials = 'all';
  3293. FTcfg.Preproc.hilbert = 'no';
  3294. FTcfg.Preproc.rectify = 'no';
  3295. FTcfg.Preproc.derivative = 'no';
  3296. % Reset GUI panel:
  3297. set(handles.CheckboxGradCorrCTF, 'Value', 1);
  3298. set(handles.DropdownGradCorrCTF, 'Value', 1);
  3299. set(handles.CheckboxHilbert, 'Value', 0);
  3300. set(handles.DropdownHilbert, 'Value', 1);
  3301. set(handles.CheckboxRectify, 'Value', 0);
  3302. set(handles.CheckboxDerivative, 'Value', 0);
  3303. % Set output handles:
  3304. handles.FTcfg = FTcfg;
  3305. OutputHandles = handles;
  3306. %=====================================================%
  3307. % FUNCTIONS TO SAVE, LOAD, AND LOCK PREPROC SETTINGS: %
  3308. %=====================================================%
  3309. %--- Executes on button press in ButtonSaveLockSettings. ---%
  3310. %-----------------------------------------------------------%
  3311. function ButtonSaveLockSettings_Callback(hObject, eventdata, handles)
  3312. if isempty(handles.name.DataID) || isempty(handles.paths.DataID)
  3313. msgbox('Warning: Create or load DataID first.', 'Warning:');
  3314. return;
  3315. end
  3316. % Check textbox settings (Most have already been checked in previous sections):
  3317. PrestimTime = str2num(get(handles.TextboxPrestimTime, 'String'));
  3318. PoststimTime = str2num(get(handles.TextboxPoststimTime, 'String'));
  3319. OverlapThreshold = str2num(get(handles.TextboxOverlapThreshold, 'String'));
  3320. if isempty(PrestimTime)
  3321. msgbox('Error: Pre-stimulus time must be specified.', 'Error:');
  3322. return;
  3323. end
  3324. if isempty(PoststimTime)
  3325. msgbox('Error: Post-stimulus time must be specified.', 'Error:');
  3326. return;
  3327. end
  3328. if isempty(OverlapThreshold)
  3329. msgbox('Error: Overlap threshold must be specified.', 'Error:')
  3330. return;
  3331. end
  3332. IncStartTime = str2num(get(handles.TextboxIncEventStartTime, 'String'));
  3333. IncEndTime = str2num(get(handles.TextboxIncEventEndTime, 'String'));
  3334. if isempty(IncStartTime) && ~isempty(handles.epoch.IncludedEvents)
  3335. msgbox('Error: Need to specify start search time for included events.', 'Error:')
  3336. return;
  3337. end
  3338. if isempty(IncEndTime) && ~isempty(handles.epoch.IncludedEvents)
  3339. msgbox('Error: Need to specify end search time for included events.', 'Error:')
  3340. return;
  3341. end
  3342. ExcStartTime = str2num(get(handles.TextboxExcEventStartTime, 'String'));
  3343. ExcEndTime = str2num(get(handles.TextboxExcEventEndTime, 'String'));
  3344. if isempty(ExcStartTime) && ~isempty(handles.epoch.ExcludedEvents)
  3345. msgbox('Error: Need to specify start search time for excluded events.', 'Error:')
  3346. return;
  3347. end
  3348. if isempty(ExcEndTime) && ~isempty(handles.epoch.ExcludedEvents)
  3349. msgbox('Error: Need to specify end search time for excluded events.', 'Error:')
  3350. return;
  3351. end
  3352. if get(handles.CheckboxDemean, 'Value') == 1
  3353. BaselineStart = str2num(get(handles.TextboxBaselineStart, 'String'));
  3354. BaselineEnd = str2num(get(handles.TextboxBaselineEnd, 'String'));
  3355. if get(handles.CheckboxBaselineWholeTrial, 'Value') == 0
  3356. if isempty(BaselineStart)
  3357. msgbox('Error: Baseline start time not specified.', 'Error:');
  3358. return;
  3359. end
  3360. if isempty(BaselineEnd)
  3361. msgbox('Error: Baseline end time not specified.', 'Error:');
  3362. return;
  3363. end
  3364. end
  3365. end
  3366. % Warning & confirmation:
  3367. prompt = {'WARNING:'; '';
  3368. 'Once settings are saved, they will be locked for current DataID.';
  3369. 'To modify settings afterwards, you will need to create new DataID';
  3370. 'or manually delete PreprocSettings .mat file.'; '';
  3371. 'Do you wish to continue?'};
  3372. ContinueSave = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'NO');
  3373. if strcmp(ContinueSave, 'NO')
  3374. return;
  3375. end
  3376. FTcfg = handles.FTcfg;
  3377. time = handles.time;
  3378. CheckSavePath([handles.paths.DataID,'/PreprocSettings.mat'], 'PreprocMEG');
  3379. save([handles.paths.DataID,'/PreprocSettings.mat'], 'FTcfg', 'time');
  3380. % Feedback:
  3381. if exist([handles.paths.DataID,'/PreprocSettings.mat'], 'file')
  3382. msgbox('PreprocSettings.mat successfully saved.')
  3383. else
  3384. msgbox('Error: Failed to save PreprocSettings.mat')
  3385. end
  3386. % Lock GUI panels:
  3387. handles.gui.LockPreprocSettings = 'on';
  3388. set(handles.ButtonSaveLockSettings, 'Enable', 'off');
  3389. set(handles.ButtonLoadPreprocSettings, 'Enable', 'off');
  3390. handles = UpdateSubjIDSettings (handles);
  3391. handles = UpdateInputDataSettings (handles);
  3392. handles = UpdateEventSettings (handles);
  3393. handles = UpdateCondIDSettings (handles);
  3394. handles = UpdateStatusSettings (handles);
  3395. handles = UpdateEpochSettings (handles);
  3396. handles = UpdateBaselineSettings (handles);
  3397. handles = UpdateGeneralFilterSettings (handles);
  3398. handles = UpdateBandstopFilterSettings (handles);
  3399. handles = UpdateDFTFilterSettings (handles);
  3400. handles = UpdateMedianFilterSettings (handles);
  3401. handles = UpdateDetrendSettings (handles);
  3402. handles = UpdateOtherAdvSettings (handles);
  3403. % Save handles:
  3404. guidata(hObject, handles);
  3405. %--- Executes on button press in ButtonLoadPreprocSettings. ---%
  3406. %--------------------------------------------------------------%
  3407. function ButtonLoadPreprocSettings_Callback(hObject, eventdata, handles)
  3408. if isempty(handles.paths.Rootpath)
  3409. msgbox('Warning: Select root directory first.', 'Warning:');
  3410. return;
  3411. end
  3412. if isempty(handles.name.DataID) || isempty(handles.paths.DataID)
  3413. msgbox('Warning: Create or load DataID first.', 'Warning:');
  3414. return;
  3415. end
  3416. % Select PreprocSettings .mat to load:
  3417. [matfile, matpath] = uigetfile([handles.paths.Rootpath,...
  3418. '/PreprocSettings.mat'], 'Load PreprocSettings from:', 'MultiSelect', 'off');
  3419. if matfile == 0
  3420. msgbox('PreprocSettings .mat was not selected.');
  3421. return;
  3422. end
  3423. % Start Waitbox:
  3424. WaitBox = StartWaitBox('LOADING PREPROC SETTINGS:');
  3425. % Load PreprocSettings from .mat:
  3426. % Note: No need to load data filetype here.
  3427. LoadedMat = load([matpath,matfile]);
  3428. handles = LoadEpochSettings (handles, LoadedMat);
  3429. handles = LoadBaselineSettings (handles, LoadedMat);
  3430. handles = LoadGeneralFilterSettings (handles, LoadedMat);
  3431. handles = LoadBandstopFilterSettings (handles, LoadedMat);
  3432. handles = LoadDFTFilterSettings (handles, LoadedMat);
  3433. handles = LoadMedianFilterSettings (handles, LoadedMat);
  3434. handles = LoadDetrendSettings (handles, LoadedMat);
  3435. handles = LoadOtherAdvSettings (handles, LoadedMat);
  3436. % Make sure settings unlocked:
  3437. handles.gui.LockPreprocSettings = 'off';
  3438. set(handles.ButtonSaveLockSettings, 'Enable', 'on');
  3439. set(handles.ButtonLoadPreprocSettings, 'Enable', 'on');
  3440. % Update settings & GUI panels:
  3441. handles = UpdateEpochSettings (handles);
  3442. handles = UpdateBaselineSettings (handles);
  3443. handles = UpdateGeneralFilterSettings (handles);
  3444. handles = UpdateBandstopFilterSettings (handles);
  3445. handles = UpdateDFTFilterSettings (handles);
  3446. handles = UpdateMedianFilterSettings (handles);
  3447. handles = UpdateDetrendSettings (handles);
  3448. handles = UpdateOtherAdvSettings (handles);
  3449. % Save handles:
  3450. guidata(hObject, handles);
  3451. close(WaitBox);
  3452. %=================================%
  3453. % FUNCTIONS TO RUN PREPROCESSING: %
  3454. %=================================%
  3455. %--- Executes on button press in ButtonEpochPreprocData. ---%
  3456. %-----------------------------------------------------------%
  3457. function ButtonEpochPreprocData_Callback(hObject, eventdata, handles)
  3458. if isempty(handles.name.DataID) || isempty(handles.paths.DataID)
  3459. msgbox('Warning: Create or load DataID first.', 'Warning:');
  3460. return;
  3461. end
  3462. if isempty(handles.name.CurrentGroupID)
  3463. msgbox('Warning: Create or load a GroupID first.', 'Warning:');
  3464. return;
  3465. end
  3466. if isempty(handles.name.CurrentCondID)
  3467. msgbox('Warning: Current CondID not selected yet.', 'Warning:');
  3468. return;
  3469. end
  3470. % Make sure Rootpath & DataID don't have spaces (will cause issues for AFNI later):
  3471. CheckSpaces1 = strfind(handles.paths.Rootpath, ' ');
  3472. CheckSpaces2 = strfind(handles.paths.DataID, ' ');
  3473. if ~isempty(CheckSpaces1) || ~isempty(CheckSpaces2)
  3474. message = {'Error: Target directory or DataID contains spaces.';
  3475. 'AFNI functions cannot read folder & file paths with spaces.';
  3476. 'AFNI functions are required for file conversions later on.'};
  3477. msgbox(message, 'Error:')
  3478. return;
  3479. end
  3480. % Check unlocked textbox settings (Most have already been checked in previous sections):
  3481. OverlapThreshold = str2num(get(handles.TextboxOverlapThreshold, 'String'));
  3482. if isempty(OverlapThreshold)
  3483. msgbox('Error: Overlap threshold must be specified.', 'Error:')
  3484. return;
  3485. end
  3486. IncStartTime = str2num(get(handles.TextboxIncEventStartTime, 'String'));
  3487. IncEndTime = str2num(get(handles.TextboxIncEventEndTime, 'String'));
  3488. if isempty(IncStartTime) && ~isempty(handles.epoch.IncludedEvents)
  3489. msgbox('Error: Need to specify start search time for included events.', 'Error:')
  3490. return;
  3491. end
  3492. if isempty(IncEndTime) && ~isempty(handles.epoch.IncludedEvents)
  3493. msgbox('Error: Need to specify end search time for included events.', 'Error:')
  3494. return;
  3495. end
  3496. ExcStartTime = str2num(get(handles.TextboxExcEventStartTime, 'String'));
  3497. ExcEndTime = str2num(get(handles.TextboxExcEventEndTime, 'String'));
  3498. if isempty(ExcStartTime) && ~isempty(handles.epoch.ExcludedEvents)
  3499. msgbox('Error: Need to specify start search time for excluded events.', 'Error:')
  3500. return;
  3501. end
  3502. if isempty(ExcEndTime) && ~isempty(handles.epoch.ExcludedEvents)
  3503. msgbox('Error: Need to specify end search time for excluded events.', 'Error:')
  3504. return;
  3505. end
  3506. % Update settings & GUI panels:
  3507. handles = UpdateSubjIDSettings (handles);
  3508. handles = UpdateInputDataSettings (handles);
  3509. handles = UpdateEventSettings (handles);
  3510. handles = UpdateCondIDSettings (handles);
  3511. handles = UpdateStatusSettings (handles);
  3512. handles = UpdateEpochSettings (handles);
  3513. handles = UpdateBaselineSettings (handles);
  3514. handles = UpdateGeneralFilterSettings (handles);
  3515. handles = UpdateBandstopFilterSettings (handles);
  3516. handles = UpdateDFTFilterSettings (handles);
  3517. handles = UpdateMedianFilterSettings (handles);
  3518. handles = UpdateDetrendSettings (handles);
  3519. handles = UpdateOtherAdvSettings (handles);
  3520. % Check if PreprocSettings.mat exists:
  3521. PreprocSettingsMat = [handles.paths.DataID,'/PreprocSettings.mat'];
  3522. if ~exist(PreprocSettingsMat, 'file')
  3523. message = {'Error: PreprocSettings.mat could not be found for DataID.';
  3524. 'To generate one, configure and save preprocessing settings in GUI.'};
  3525. msgbox(message, 'Error:');
  3526. return;
  3527. end
  3528. % Since certain time settings are NOT locked along with other settings,
  3529. % need to update PreprocSettings.mat with current time settings.
  3530. time = handles.time;
  3531. save(PreprocSettingsMat, 'time', '-append');
  3532. % Save copy of PreprocInputMEG for current CondID:
  3533. prompt = {'Save a copy of the CURRENT input settings?';
  3534. [' Group: ',handles.name.CurrentGroupID];
  3535. [' Cond: ',handles.name.CurrentCondID]};
  3536. SaveInput = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'YES');
  3537. if strcmp(SaveInput, 'YES')
  3538. ButtonSaveInput_Callback(hObject, eventdata, handles);
  3539. end
  3540. % Check parallel computing:
  3541. CheckOpenPCT
  3542. % Run command to preprocess & epoch data:
  3543. PreprocInputMEG.name.DataID = handles.name.DataID;
  3544. PreprocInputMEG.name.SubjID = handles.name.SubjID;
  3545. PreprocInputMEG.name.CurrentGroupID = handles.name.CurrentGroupID;
  3546. PreprocInputMEG.name.CurrentCondID = handles.name.CurrentCondID;
  3547. PreprocInputMEG.paths = handles.paths;
  3548. PreprocInputMEG.epoch.TargetMarkers = handles.epoch.TargetMarkers;
  3549. PreprocInputMEG.epoch.IncludedEvents = handles.epoch.IncludedEvents;
  3550. PreprocInputMEG.epoch.ExcludedEvents = handles.epoch.ExcludedEvents;
  3551. PreprocInputMEG.gui.DataFiletype = handles.gui.DataFiletype;
  3552. disp('PREPROCESSING DATA:')
  3553. MEGpipeline_PreprocMEG(PreprocSettingsMat, PreprocInputMEG);
  3554. % Update Status:
  3555. set(handles.CheckboxShowOutputStatus, 'Value', 1);
  3556. handles = DetectStatus(handles);
  3557. handles = UpdateStatusSettings (handles);
  3558. % Clear CurrentCondID and AddedEvents for next CondID:
  3559. % Note: No need to reset DetectedEvents or CondID folders.
  3560. handles.name.CurrentCondID = [];
  3561. handles.paths.CurrentCondID = [];
  3562. handles.epoch.TargetMarkers = [];
  3563. handles.epoch.IncludedEvents = [];
  3564. handles.epoch.ExcludedEvents = [];
  3565. set(handles.TextboxCurrentCondID, 'String', []);
  3566. set(handles.ListboxTargetMarkers, 'String', []);
  3567. set(handles.ListboxIncludedEvents, 'String', []);
  3568. set(handles.ListboxExcludedEvents, 'String', []);
  3569. handles = UpdateEventSettings (handles);
  3570. handles = UpdateCondIDSettings (handles);
  3571. % Save handles:
  3572. guidata(hObject, handles);
  3573. %=================================%
  3574. % FUNCTION TO OPEN MODAL WAITBOX: %
  3575. %=================================%
  3576. function WaitBox = StartWaitBox(TextString)
  3577. WaitBox = dialog('Units', 'pixels', 'Position', [500 500 300 40],...
  3578. 'Windowstyle', 'modal', 'NextPlot', 'new', 'Name', 'Please Wait:');
  3579. uicontrol('Parent', WaitBox, 'Units', 'pixels', 'Position', [20 10 250 20],...
  3580. 'Style', 'text', 'String', TextString, 'FontWeight', 'bold');
  3581. movegui(WaitBox, 'center');
  3582. %============================%
  3583. % GUIDE CREATEFCN FUNCTIONS: %
  3584. %============================%
  3585. % --- Executes during object creation, after setting all properties.
  3586. function TextboxRootpath_CreateFcn(hObject, eventdata, handles)
  3587. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3588. set(hObject,'BackgroundColor','white');
  3589. end
  3590. % --- Executes during object creation, after setting all properties.
  3591. function TextboxDataID_CreateFcn(hObject, eventdata, handles)
  3592. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3593. set(hObject,'BackgroundColor','white');
  3594. end
  3595. % --- Executes during object creation, after setting all properties.
  3596. function TextboxGroupID_CreateFcn(hObject, eventdata, handles)
  3597. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3598. set(hObject,'BackgroundColor','white');
  3599. end
  3600. % --- Executes during object creation, after setting all properties.
  3601. function ListboxSubjID_CreateFcn(hObject, eventdata, handles)
  3602. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3603. set(hObject,'BackgroundColor','white');
  3604. end
  3605. % --- Executes during object creation, after setting all properties.
  3606. function TextboxSubjID_CreateFcn(hObject, eventdata, handles)
  3607. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3608. set(hObject,'BackgroundColor','white');
  3609. end
  3610. % --- Executes during object creation, after setting all properties.
  3611. function DropdownDataFiletype_CreateFcn(hObject, eventdata, handles)
  3612. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3613. set(hObject,'BackgroundColor','white');
  3614. end
  3615. % --- Executes during object creation, after setting all properties.
  3616. function ListboxInputData_CreateFcn(hObject, eventdata, handles)
  3617. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3618. set(hObject,'BackgroundColor','white');
  3619. end
  3620. % --- Executes during object creation, after setting all properties.
  3621. function ListboxDetectedEvents_CreateFcn(hObject, eventdata, handles)
  3622. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3623. set(hObject,'BackgroundColor','white');
  3624. end
  3625. % --- Executes during object creation, after setting all properties.
  3626. function ListboxTargetMarkers_CreateFcn(hObject, eventdata, handles)
  3627. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3628. set(hObject,'BackgroundColor','white');
  3629. end
  3630. % --- Executes during object creation, after setting all properties.
  3631. function ListboxIncludedEvents_CreateFcn(hObject, eventdata, handles)
  3632. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3633. set(hObject,'BackgroundColor','white');
  3634. end
  3635. % --- Executes during object creation, after setting all properties.
  3636. function ListboxExcludedEvents_CreateFcn(hObject, eventdata, handles)
  3637. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3638. set(hObject,'BackgroundColor','white');
  3639. end
  3640. % --- Executes during object creation, after setting all properties.
  3641. function ListboxCondID_CreateFcn(hObject, eventdata, handles)
  3642. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3643. set(hObject,'BackgroundColor','white');
  3644. end
  3645. % --- Executes during object creation, after setting all properties.
  3646. function TextboxCurrentCondID_CreateFcn(hObject, eventdata, handles)
  3647. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3648. set(hObject,'BackgroundColor','white');
  3649. end
  3650. % --- Executes during object creation, after setting all properties.
  3651. function ListboxStatus_CreateFcn(hObject, eventdata, handles)
  3652. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3653. set(hObject,'BackgroundColor','white');
  3654. end
  3655. % --- Executes during object creation, after setting all properties.
  3656. function TextboxPrestimTime_CreateFcn(hObject, eventdata, handles)
  3657. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3658. set(hObject,'BackgroundColor','white');
  3659. end
  3660. % --- Executes during object creation, after setting all properties.
  3661. function TextboxPoststimTime_CreateFcn(hObject, eventdata, handles)
  3662. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3663. set(hObject,'BackgroundColor','white');
  3664. end
  3665. % --- Executes during object creation, after setting all properties.
  3666. function TextboxOverlapThreshold_CreateFcn(hObject, eventdata, handles)
  3667. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3668. set(hObject,'BackgroundColor','white');
  3669. end
  3670. % --- Executes during object creation, after setting all properties.
  3671. function TextboxIncEventStartTime_CreateFcn(hObject, eventdata, handles)
  3672. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3673. set(hObject,'BackgroundColor','white');
  3674. end
  3675. % --- Executes during object creation, after setting all properties.
  3676. function TextboxIncEventEndTime_CreateFcn(hObject, eventdata, handles)
  3677. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3678. set(hObject,'BackgroundColor','white');
  3679. end
  3680. % --- Executes during object creation, after setting all properties.
  3681. function TextboxExcEventStartTime_CreateFcn(hObject, eventdata, handles)
  3682. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3683. set(hObject,'BackgroundColor','white');
  3684. end
  3685. % --- Executes during object creation, after setting all properties.
  3686. function TextboxExcEventEndTime_CreateFcn(hObject, eventdata, handles)
  3687. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3688. set(hObject,'BackgroundColor','white');
  3689. end
  3690. % --- Executes during object creation, after setting all properties.
  3691. function TextboxPaddingLength_CreateFcn(hObject, eventdata, handles)
  3692. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3693. set(hObject,'BackgroundColor','white');
  3694. end
  3695. % --- Executes during object creation, after setting all properties.
  3696. function TextboxBaselineStart_CreateFcn(hObject, eventdata, handles)
  3697. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3698. set(hObject,'BackgroundColor','white');
  3699. end
  3700. % --- Executes during object creation, after setting all properties.
  3701. function TextboxBaselineEnd_CreateFcn(hObject, eventdata, handles)
  3702. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3703. set(hObject,'BackgroundColor','white');
  3704. end
  3705. % --- Executes during object creation, after setting all properties.
  3706. function TextboxHighpassFreq_CreateFcn(hObject, eventdata, handles)
  3707. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3708. set(hObject,'BackgroundColor','white');
  3709. end
  3710. % --- Executes during object creation, after setting all properties.
  3711. function TextboxLowpassFreq_CreateFcn(hObject, eventdata, handles)
  3712. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3713. set(hObject,'BackgroundColor','white');
  3714. end
  3715. % --- Executes during object creation, after setting all properties.
  3716. function DropdownPassFilterDir_CreateFcn(hObject, eventdata, handles)
  3717. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3718. set(hObject,'BackgroundColor','white');
  3719. end
  3720. % --- Executes during object creation, after setting all properties.
  3721. function DropdownPassFilterType_CreateFcn(hObject, eventdata, handles)
  3722. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3723. set(hObject,'BackgroundColor','white');
  3724. end
  3725. % --- Executes during object creation, after setting all properties.
  3726. function TextboxPassFilterOrder_CreateFcn(hObject, eventdata, handles)
  3727. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3728. set(hObject,'BackgroundColor','white');
  3729. end
  3730. % --- Executes during object creation, after setting all properties.
  3731. function DropdownPassFilterInstability_CreateFcn(hObject, eventdata, handles)
  3732. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3733. set(hObject,'BackgroundColor','white');
  3734. end
  3735. % --- Executes during object creation, after setting all properties.
  3736. function TextboxHighstopFreq_CreateFcn(hObject, eventdata, handles)
  3737. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3738. set(hObject,'BackgroundColor','white');
  3739. end
  3740. % --- Executes during object creation, after setting all properties.
  3741. function TextboxLowstopFreq_CreateFcn(hObject, eventdata, handles)
  3742. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3743. set(hObject,'BackgroundColor','white');
  3744. end
  3745. % --- Executes during object creation, after setting all properties.
  3746. function DropdownBandstopFilterDir_CreateFcn(hObject, eventdata, handles)
  3747. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3748. set(hObject,'BackgroundColor','white');
  3749. end
  3750. % --- Executes during object creation, after setting all properties.
  3751. function DropdownBandstopFilterType_CreateFcn(hObject, eventdata, handles)
  3752. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3753. set(hObject,'BackgroundColor','white');
  3754. end
  3755. % --- Executes during object creation, after setting all properties.
  3756. function TextboxBandstopFilterOrder_CreateFcn(hObject, eventdata, handles)
  3757. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3758. set(hObject,'BackgroundColor','white');
  3759. end
  3760. % --- Executes during object creation, after setting all properties.
  3761. function DropdownBandstopFilterInstability_CreateFcn(hObject, eventdata, handles)
  3762. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3763. set(hObject,'BackgroundColor','white');
  3764. end
  3765. % --- Executes during object creation, after setting all properties.
  3766. function TextboxDFTcustom_CreateFcn(hObject, eventdata, handles)
  3767. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3768. set(hObject,'BackgroundColor','white');
  3769. end
  3770. % --- Executes during object creation, after setting all properties.
  3771. function TextboxMedianFilterOrder_CreateFcn(hObject, eventdata, handles)
  3772. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3773. set(hObject,'BackgroundColor','white');
  3774. end
  3775. % --- Executes during object creation, after setting all properties.
  3776. function TextboxPolyremovalOrder_CreateFcn(hObject, eventdata, handles)
  3777. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3778. set(hObject,'BackgroundColor','white');
  3779. end
  3780. % --- Executes during object creation, after setting all properties.
  3781. function DropdownGradCorrCTF_CreateFcn(hObject, eventdata, handles)
  3782. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3783. set(hObject,'BackgroundColor','white');
  3784. end
  3785. % --- Executes during object creation, after setting all properties.
  3786. function DropdownHilbert_CreateFcn(hObject, eventdata, handles)
  3787. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3788. set(hObject,'BackgroundColor','white');
  3789. end